task-h.1 complate

This commit is contained in:
phaichayon
2026-06-16 14:25:26 +07:00
parent edee45375e
commit 9ae41e4f2c
14 changed files with 2238 additions and 201 deletions

View File

@@ -350,6 +350,7 @@ async function syncEntityStatusFromApproval(
}
if (approvalStatus === APPROVAL_REQUEST_STATUSES.approved) {
// TODO(task-h.1): add an async hook/job to auto-generate approved PDFs after final approval.
await syncQuotationStatusFromApproval(entityId, organizationId, userId, 'approved');
return;
}

View File

@@ -107,13 +107,17 @@ export async function generatePdfFromTemplate(input: GeneratePdfFromTemplateInpu
error instanceof Error &&
(error.message.includes('Font "') || error.message.includes('fontKitFont.layout'))
) {
pdf = await generate({
...generatorInput,
template: normalizeTemplateFonts(input.template),
options: undefined
});
try {
pdf = await generate({
...generatorInput,
template: normalizeTemplateFonts(input.template),
options: undefined
});
} catch {
throw new AuthError('Unable to generate PDF from the current template', 500);
}
} else {
throw error;
throw new AuthError('Unable to generate PDF from the current template', 500);
}
}
@@ -155,8 +159,15 @@ async function persistApprovedQuotationArtifact(args: {
const absolutePath = path.join(directory, safeFileName);
const publicPath = `/generated/quotations/${args.organizationId}/${safeFileName}`;
await writeFile(absolutePath, args.buffer);
const fileStats = await stat(absolutePath);
try {
await writeFile(absolutePath, args.buffer);
} catch {
throw new AuthError('Unable to persist approved PDF to local storage', 500);
}
const fileStats = await stat(absolutePath).catch(() => {
throw new AuthError('Approved PDF was written but could not be verified on disk', 500);
});
await db
.update(crmQuotations)
@@ -289,7 +300,9 @@ export async function getStoredApprovedQuotationPdf(
const relativePath = quotation.approvedPdfUrl.replace(/^\//, '');
const absolutePath = path.join(process.cwd(), 'public', relativePath);
const buffer = await readFile(absolutePath);
const buffer = await readFile(absolutePath).catch(() => {
throw new AuthError('Approved PDF file is missing from local storage', 404);
});
return {
buffer,