diff --git a/back/src/bsda/converter.ts b/back/src/bsda/converter.ts index aa83115910..cade867424 100644 --- a/back/src/bsda/converter.ts +++ b/back/src/bsda/converter.ts @@ -40,7 +40,8 @@ import type { BsdaWorkerCertification, CompanyInput, Bsda, - BsdaTransporterInput + BsdaTransporterInput, + BsdaRevisionRequestOperationNextDestination } from "@td/codegen-back"; import { Prisma, @@ -663,6 +664,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 @@ -710,7 +716,11 @@ export function expandBsdaRevisionRequestContent( operation: nullIfNoValues({ code: bsdaRevisionRequest.destinationOperationCode, mode: bsdaRevisionRequest.destinationOperationMode, - description: bsdaRevisionRequest.destinationOperationDescription + description: bsdaRevisionRequest.destinationOperationDescription, + nextDestination: + nullIfNoValues({ + cap: bsdaRevisionRequest.destinationOperationNextDestinationCap + }) }), reception: nullIfNoValues({ weight: bsdaRevisionRequest.destinationReceptionWeight diff --git a/back/src/bsda/repository/revisionRequest/accept.ts b/back/src/bsda/repository/revisionRequest/accept.ts index de7b112d9f..ffc7d6e9ca 100644 --- a/back/src/bsda/repository/revisionRequest/accept.ts +++ b/back/src/bsda/repository/revisionRequest/accept.ts @@ -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, diff --git a/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/createRevisionRequest.integration.ts b/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/createRevisionRequest.integration.ts index f19cb26f37..98ac4f80a7 100644 --- a/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/createRevisionRequest.integration.ts +++ b/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/createRevisionRequest.integration.ts @@ -21,6 +21,14 @@ const CREATE_BSDA_REVISION_REQUEST = ` } content { waste { code } + destination { + cap + operation { + nextDestination { + cap + } + } + } } authoringCompany { siret @@ -349,6 +357,7 @@ describe("Mutation.createBsdaRevisionRequest", () => { }); expect(data.createBsdaRevisionRequest.content).toEqual({ + destination: null, waste: { code: "16 01 11*" } }); }); @@ -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, + 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, + 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"); + }); }); diff --git a/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/submitRevisionRequestApproval.integration.ts b/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/submitRevisionRequestApproval.integration.ts index ab2423a19e..0c23720c7b 100644 --- a/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/submitRevisionRequestApproval.integration.ts +++ b/back/src/bsda/resolvers/mutations/revisionRequest/__tests__/submitRevisionRequestApproval.integration.ts @@ -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, + 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, + 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" + ); + }); }); diff --git a/back/src/bsda/resolvers/mutations/revisionRequest/createRevisionRequest.ts b/back/src/bsda/resolvers/mutations/revisionRequest/createRevisionRequest.ts index cb87c5571a..657c2be26f 100644 --- a/back/src/bsda/resolvers/mutations/revisionRequest/createRevisionRequest.ts +++ b/back/src/bsda/resolvers/mutations/revisionRequest/createRevisionRequest.ts @@ -56,6 +56,7 @@ export type RevisionRequestContent = Pick< | "destinationReceptionWeight" | "destinationOperationCode" | "destinationOperationDescription" + | "destinationOperationNextDestinationCap" | "brokerCompanyName" | "brokerCompanySiret" | "brokerCompanyAddress" @@ -240,6 +241,7 @@ const schema = rawBsdaSchema destinationOperationMode: true, destinationOperationDescription: true, destinationReceptionWeight: true, + destinationOperationNextDestinationCap: true, brokerCompanyName: true, brokerCompanySiret: true, brokerCompanyAddress: true, diff --git a/back/src/bsda/typeDefs/bsda.inputs.graphql b/back/src/bsda/typeDefs/bsda.inputs.graphql index 24f6f186e7..0b5a4b9283 100644 --- a/back/src/bsda/typeDefs/bsda.inputs.graphql +++ b/back/src/bsda/typeDefs/bsda.inputs.graphql @@ -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 { diff --git a/back/src/bsda/typeDefs/bsda.objects.graphql b/back/src/bsda/typeDefs/bsda.objects.graphql index 0b7043ad2f..b30cc3792b 100644 --- a/back/src/bsda/typeDefs/bsda.objects.graphql +++ b/back/src/bsda/typeDefs/bsda.objects.graphql @@ -434,6 +434,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 { diff --git a/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts b/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts index e668202ce9..46b23ec6a1 100644 --- a/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts +++ b/front/src/Apps/Dashboard/Components/Revision/revisionMapper.ts @@ -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)", @@ -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, @@ -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 diff --git a/front/src/Apps/Dashboard/Components/RevisionRequestList/bsda/request/BsdaRequestRevision.tsx b/front/src/Apps/Dashboard/Components/RevisionRequestList/bsda/request/BsdaRequestRevision.tsx index 6381721be0..826a3eab57 100644 --- a/front/src/Apps/Dashboard/Components/RevisionRequestList/bsda/request/BsdaRequestRevision.tsx +++ b/front/src/Apps/Dashboard/Components/RevisionRequestList/bsda/request/BsdaRequestRevision.tsx @@ -162,6 +162,8 @@ export function BsdaRequestRevision({ bsda }: Props) { setValue("waste.sealNumbers", newPlates); }; + const hasTTR = bsda.destination?.operation?.nextDestination?.company?.orgId; + return (

@@ -255,13 +257,17 @@ export function BsdaRequestRevision({ bsda }: Props) { + {hasTTR && ( + + + + )} +