task-h.4
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
getQuotationDocumentPreviewData,
|
||||
prepareApprovedQuotationSnapshot
|
||||
} from '@/features/crm/quotations/document/server/service';
|
||||
import type { ApprovedQuotationSnapshot } from '@/features/crm/quotations/document/types';
|
||||
import { getQuotationDetail } from '@/features/crm/quotations/server/service';
|
||||
|
||||
type GeneratePdfFromTemplateInput = {
|
||||
@@ -323,14 +324,23 @@ export async function generateApprovedQuotationPdf(
|
||||
userId: string
|
||||
): Promise<GeneratedQuotationPdf> {
|
||||
const preview = await getQuotationDocumentPreviewData(quotationId, organizationId);
|
||||
const quotation = await getQuotationDetail(quotationId, organizationId);
|
||||
const approvedSnapshot = quotation.approvedSnapshot as ApprovedQuotationSnapshot | null;
|
||||
|
||||
if (preview.documentData.quotation.statusCode !== 'approved') {
|
||||
throw new AuthError('Only approved quotations can generate approved PDF', 400);
|
||||
}
|
||||
|
||||
const snapshotTemplateInput =
|
||||
approvedSnapshot &&
|
||||
approvedSnapshot.quotationId === quotationId &&
|
||||
approvedSnapshot.templateInput &&
|
||||
typeof approvedSnapshot.templateInput === 'object'
|
||||
? approvedSnapshot.templateInput
|
||||
: null;
|
||||
const buffer = await generatePdfFromTemplate({
|
||||
template: preview.template.version.schemaJson as Template,
|
||||
inputs: [preview.templateInput]
|
||||
inputs: [snapshotTemplateInput ?? preview.templateInput]
|
||||
});
|
||||
const fileName = `${preview.documentData.quotation.code}-approved.pdf`;
|
||||
const artifact = await persistApprovedQuotationArtifact({
|
||||
|
||||
Reference in New Issue
Block a user