Skip to content

Commit

Permalink
feat: modified seal rule on destinationCap
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelFerrand committed Nov 26, 2024
1 parent e5752aa commit 09bacce
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion back/src/bsda/validation/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ const sealedFromEmissionExceptAddOrRemoveNextDestination: GetBsdaSignatureTypeFn
return isEmitter ? "WORK" : "EMISSION";
};

const sealedFromEmissionExceptIfWorker: GetBsdaSignatureTypeFn<ZodBsda> = (
_,
context
) => {
// Si entreprise de travaux: on peut modifier jusqu'à l'étape de transport
// Sinon, scellé dès la signature émetteur
const persisted = context!.persisted;
const hasWorker = persisted?.workerCompanySiret;

return hasWorker ? "TRANSPORT" : "EMISSION";
};

/**
* Renvoie la signature émetteur s'il n'y a pas d'entreprise de travaux sur le BSDA.
* Sinon, renvoie la signature de l'entreprise de travaux.
Expand Down Expand Up @@ -434,7 +446,7 @@ export const bsdaEditionRules: BsdaEditionRules = {
},
destinationCap: {
readableFieldName: "le CAP du destinataire",
sealed: { from: sealedFromEmissionExceptAddOrRemoveNextDestination },
sealed: { from: sealedFromEmissionExceptIfWorker },
required: {
from: "EMISSION",
when: bsda =>
Expand Down

0 comments on commit 09bacce

Please sign in to comment.