mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 20:40:55 +00:00
feat: implement PDF regeneration for contracts and enhance document upload handling in clearance sections
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user