Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA-15631] Ajout de la possibilité de réviser le CAP de l'exutoire et du TTR lorsqu'un TTR a été visé #3895

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions back/src/bsda/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import type {
BsdaWorkerCertification,
CompanyInput,
Bsda,
BsdaTransporterInput
BsdaTransporterInput,
BsdaRevisionRequestOperationNextDestination
} from "@td/codegen-back";
import {
Prisma,
Expand Down Expand Up @@ -662,6 +663,11 @@ export function flattenBsdaRevisionRequestInput(
)
)
),
destinationOperationNextDestinationCap: chain(reviewContent, r =>
chain(r.destination, d =>
chain(d.operation, o => chain(o.nextDestination, n => n.cap))
)
),
isCanceled: undefinedOrDefault(
chain(reviewContent, c => chain(c, r => r.isCanceled)),
false
Expand Down Expand Up @@ -709,7 +715,11 @@ export function expandBsdaRevisionRequestContent(
operation: nullIfNoValues<BsdaRevisionRequestOperation>({
code: bsdaRevisionRequest.destinationOperationCode,
mode: bsdaRevisionRequest.destinationOperationMode,
description: bsdaRevisionRequest.destinationOperationDescription
description: bsdaRevisionRequest.destinationOperationDescription,
nextDestination:
nullIfNoValues<BsdaRevisionRequestOperationNextDestination>({
cap: bsdaRevisionRequest.destinationOperationNextDestinationCap
})
}),
reception: nullIfNoValues<BsdaRevisionRequestReception>({
weight: bsdaRevisionRequest.destinationReceptionWeight
Expand Down
2 changes: 2 additions & 0 deletions back/src/bsda/repository/revisionRequest/accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ async function getUpdateFromRevisionRequest(
destinationOperationDescription:
revisionRequest.destinationOperationDescription,
destinationOperationMode: revisionRequest.destinationOperationMode,
destinationOperationNextDestinationCap:
revisionRequest.destinationOperationNextDestinationCap,
brokerCompanyName: revisionRequest.brokerCompanyName,
brokerCompanySiret: revisionRequest.brokerCompanySiret,
brokerCompanyAddress: revisionRequest.brokerCompanyAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const CREATE_BSDA_REVISION_REQUEST = `
}
content {
waste { code }
destination {
cap
operation {
nextDestination {
cap
}
}
}
}
authoringCompany {
siret
Expand Down Expand Up @@ -349,6 +357,7 @@ describe("Mutation.createBsdaRevisionRequest", () => {
});

expect(data.createBsdaRevisionRequest.content).toEqual({
destination: null,
waste: { code: "16 01 11*" }
});
});
Expand Down Expand Up @@ -795,4 +804,87 @@ describe("Mutation.createBsdaRevisionRequest", () => {
"Vous devez saisir la description du conditionnement quand le type de conditionnement est 'Autre'"
);
});

it("should be possible to review the destination CAP", async () => {
// Given
const { company: destinationCompany } = await userWithCompanyFactory(
"ADMIN"
);
const { user, company } = await userWithCompanyFactory("ADMIN");
const bsda = await bsdaFactory({
opt: {
emitterCompanySiret: company.siret,
destinationCompanySiret: destinationCompany.siret,
destinationCap: "DESTINATION-SIRET",
status: "SENT"
}
});

// When
const { mutate } = makeClient(user);
const { errors, data } = await mutate<
Pick<Mutation, "createBsdaRevisionRequest">,
MutationCreateBsdaRevisionRequestArgs
>(CREATE_BSDA_REVISION_REQUEST, {
variables: {
input: {
bsdaId: bsda.id,
content: { destination: { cap: "NEW-DESTINATION-CAP" } },
comment: "A comment",
authoringCompanySiret: company.siret!
}
}
});

// Then
expect(errors).toBeUndefined();
expect(data.createBsdaRevisionRequest?.content?.destination?.cap).toBe(
"NEW-DESTINATION-CAP"
);
});

it("should be possible to review the operation next destination CAP", async () => {
// Given
const { company: destinationCompany } = await userWithCompanyFactory(
"ADMIN"
);
const { user, company } = await userWithCompanyFactory("ADMIN");
const bsda = await bsdaFactory({
opt: {
emitterCompanySiret: company.siret,
destinationCompanySiret: destinationCompany.siret,
destinationOperationNextDestinationCap: "NEXT-DESTINATION-CAP",
status: "SENT"
}
});

// When
const { mutate } = makeClient(user);
const { errors, data } = await mutate<
Pick<Mutation, "createBsdaRevisionRequest">,
MutationCreateBsdaRevisionRequestArgs
>(CREATE_BSDA_REVISION_REQUEST, {
variables: {
input: {
bsdaId: bsda.id,
content: {
destination: {
operation: {
nextDestination: { cap: "NEW-NEXT-DESTINATION-CAP" }
}
}
},
comment: "A comment",
authoringCompanySiret: company.siret!
}
}
});

// Then
expect(errors).toBeUndefined();
expect(
data.createBsdaRevisionRequest?.content?.destination?.operation
?.nextDestination?.cap
).toBe("NEW-NEXT-DESTINATION-CAP");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1076,4 +1076,94 @@ describe("Mutation.submitBsdaRevisionRequestApproval", () => {
expect(updatedInitialBsda.finalOperations).toHaveLength(1);
}
);

it("should be able to update the destination cap", async () => {
// Given
const { company: companyOfSomeoneElse } = await userWithCompanyFactory(
"ADMIN"
);
const { user, company } = await userWithCompanyFactory("ADMIN");
const { mutate } = makeClient(user);

const bsda = await bsdaFactory({
opt: {
emitterCompanySiret: companyOfSomeoneElse.siret,
destinationCap: "DESTINATION-CAP"
}
});

const revisionRequest = await prisma.bsdaRevisionRequest.create({
data: {
bsdaId: bsda.id,
authoringCompanyId: companyOfSomeoneElse.id,
approvals: { create: { approverSiret: company.siret! } },
destinationCap: "NEW-DESTINATION-CAP",
comment: ""
}
});

// When
await mutate<
Pick<Mutation, "submitBsdaRevisionRequestApproval">,
MutationSubmitBsdaRevisionRequestApprovalArgs
>(SUBMIT_BSDA_REVISION_REQUEST_APPROVAL, {
variables: {
id: revisionRequest.id,
isApproved: true
}
});

// Then
const updatedBsda = await prisma.bsda.findUniqueOrThrow({
where: { id: bsda.id }
});

expect(updatedBsda.destinationCap).toBe("NEW-DESTINATION-CAP");
});

it("should be able to update the operation next destination cap", async () => {
// Given
const { company: companyOfSomeoneElse } = await userWithCompanyFactory(
"ADMIN"
);
const { user, company } = await userWithCompanyFactory("ADMIN");
const { mutate } = makeClient(user);

const bsda = await bsdaFactory({
opt: {
emitterCompanySiret: companyOfSomeoneElse.siret,
destinationOperationNextDestinationCap: "NEXT-DESTINATION-CAP"
}
});

const revisionRequest = await prisma.bsdaRevisionRequest.create({
data: {
bsdaId: bsda.id,
authoringCompanyId: companyOfSomeoneElse.id,
approvals: { create: { approverSiret: company.siret! } },
destinationOperationNextDestinationCap: "NEW-NEXT-DESTINATION-CAP",
comment: ""
}
});

// When
await mutate<
Pick<Mutation, "submitBsdaRevisionRequestApproval">,
MutationSubmitBsdaRevisionRequestApprovalArgs
>(SUBMIT_BSDA_REVISION_REQUEST_APPROVAL, {
variables: {
id: revisionRequest.id,
isApproved: true
}
});

// Then
const updatedBsda = await prisma.bsda.findUniqueOrThrow({
where: { id: bsda.id }
});

expect(updatedBsda.destinationOperationNextDestinationCap).toBe(
"NEW-NEXT-DESTINATION-CAP"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type RevisionRequestContent = Pick<
| "destinationReceptionWeight"
| "destinationOperationCode"
| "destinationOperationDescription"
| "destinationOperationNextDestinationCap"
| "brokerCompanyName"
| "brokerCompanySiret"
| "brokerCompanyAddress"
Expand Down Expand Up @@ -240,6 +241,7 @@ const schema = rawBsdaSchema
destinationOperationMode: true,
destinationOperationDescription: true,
destinationReceptionWeight: true,
destinationOperationNextDestinationCap: true,
brokerCompanyName: true,
brokerCompanySiret: true,
brokerCompanyAddress: true,
Expand Down
8 changes: 8 additions & 0 deletions back/src/bsda/typeDefs/bsda.inputs.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ input BsdaRevisionRequestOperationInput {

"Description de l'opération"
description: String

"Informations relatives au TTR"
nextDestination: BsdaRevisionRequestNextDestinationInput
}

input BsdaRevisionRequestNextDestinationInput {
"N° de CAP (le cas échéant)"
cap: String
}

input BsdaRevisionRequestWasteInput {
Expand Down
8 changes: 8 additions & 0 deletions back/src/bsda/typeDefs/bsda.objects.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ type BsdaRevisionRequestOperation {

"Description de l'opération"
description: String

"Informations relatives au TTR"
nextDestination: BsdaRevisionRequestOperationNextDestination
}

type BsdaRevisionRequestOperationNextDestination {
"N° de CAP"
cap: String
}

type BsdaRevisionRequestWaste {
Expand Down
14 changes: 13 additions & 1 deletion front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export enum DataNameEnum {
POLLUANTS_ORG = "Présence de polluants organiques persistants",
CAP_FINAL_DEST = "CAP (destination finale)",
CAP = "CAP",
CAP_EXUTOIRE = "CAP de l'exutoire",
TTR_CAP = "CAP du TTR",
SAMPLE_NUMBER = "Numéro d'échantillon",
CAP_TEMP_STORAGE = "CAP (entreposage provisoire ou reconditionnement)",
QTY_ESTIMATED = "Poids estimé (en tonnes)",
Expand Down Expand Up @@ -133,6 +135,9 @@ export const mapRevision = (
review: FormRevisionRequest & BsdaRevisionRequest & BsdasriRevisionRequest,
bsdName: string
): ReviewInterface => {
const hasTTR =
review?.[bsdName]?.destination?.operation?.nextDestination?.company?.orgId;

return {
id: review?.id,
readableId: review?.[bsdName]?.readableId || review?.[bsdName]?.id,
Expand Down Expand Up @@ -264,10 +269,17 @@ export const mapRevision = (
dataNewValue: review?.content?.temporaryStorageDetail?.destination?.cap
},
{
dataName: DataNameEnum.CAP,
dataName: hasTTR ? DataNameEnum.TTR_CAP : DataNameEnum.CAP_EXUTOIRE,
dataOldValue: review?.[bsdName]?.destination?.cap,
dataNewValue: review?.content?.destination?.cap
},
{
dataName: hasTTR ? DataNameEnum.CAP_EXUTOIRE : DataNameEnum.TTR_CAP,
dataOldValue:
review?.[bsdName]?.destination?.operation?.nextDestination?.cap,
dataNewValue:
review?.content?.destination?.operation?.nextDestination?.cap
},
{
dataName: review?.[bsdName]?.form?.temporaryStorageDetail
? DataNameEnum.CAP_TEMP_STORAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export function BsdaRequestRevision({ bsda }: Props) {
setValue("waste.sealNumbers", newPlates);
};

const hasTTR = bsda.destination?.operation?.nextDestination?.company?.orgId;

return (
<div className={styles.container}>
<h2 className={styles.title}>
Expand Down Expand Up @@ -255,20 +257,43 @@ export function BsdaRequestRevision({ bsda }: Props) {
</RhfReviewableField>

<RhfReviewableField
title="CAP"
title={hasTTR ? "CAP du TTR" : "CAP"}
value={bsda.destination?.cap}
path="destination.cap"
defaultValue={initialBsdaReview.destination.cap}
>
<Input
label="Numéro de CAP"
label={
hasTTR
? "Numéro de CAP du TTR"
: "Numéro de CAP de l'exutoire"
}
className="fr-col-6"
nativeInputProps={{
...register("destination.cap")
}}
/>
</RhfReviewableField>

{hasTTR && (
<RhfReviewableField
title="CAP de l'exutoire"
value={bsda.destination?.operation?.nextDestination?.cap}
path="bsda.destination.operation.nextDestination.cap"
defaultValue={
initialBsdaReview.destination.operation.nextDestination.cap
}
>
<Input
label="Numéro de CAP de l'exutoire"
className="fr-col-6"
nativeInputProps={{
...register("destination.operation.nextDestination.cap")
}}
/>
</RhfReviewableField>
)}

<RhfReviewableField
title="Conditionnement"
path="packagings"
Expand Down
Loading
Loading