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-15342] Le champ destinationCap du BSDA est scellé à partir de l'étape de transport (ou émission si pas d'entreprise de travaux) #3778

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
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: 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;
GaelFerrand marked this conversation as resolved.
Show resolved Hide resolved
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