feat: implement PDF regeneration for contracts and enhance document upload handling in clearance sections

This commit is contained in:
Marshal
2026-06-28 20:12:45 +00:00
parent 1b37914201
commit fc1adce909
5 changed files with 362 additions and 269 deletions

View File

@@ -302,6 +302,26 @@ export class ContractTransitionService {
return { view, html, signatures: view.signatures };
}
/**
* Rebuild the stored `contract` PDF from the current aggregate (now including
* the latest signatures) so the downloaded/viewed file matches the live HTML
* view. Best-effort — a Chromium hiccup must never fail the signing
* transaction; the doc still re-renders live on /contract/view.
*/
private async regenerateContractPdf(
contractId: string,
reference: string,
): Promise<void> {
try {
const { view } = await this.documentViewModelBuilder.build(contractId);
await this.upsertContractPdf(contractId, reference, view);
} catch (err) {
this.logger.warn(
`Signed contract PDF regen deferred for ${reference}: ${err}. It re-renders live on view.`,
);
}
}
/** Render the contract PDF and upsert it as the `contract` file on the contract. */
private async upsertContractPdf(
contractId: string,
@@ -458,6 +478,7 @@ export class ContractTransitionService {
status: 'SIGNED_CUSTOMER',
customerSignedAt: new Date(),
} as never);
await this.regenerateContractPdf(contractId, contract.reference);
return this.contractsService.findById(contractId);
}
@@ -517,6 +538,7 @@ export class ContractTransitionService {
}
await this.contractsRepository.update(contractId, updates as never);
await this.regenerateContractPdf(contractId, contract.reference);
return this.contractsService.findById(contractId);
}