task-d.5.6

This commit is contained in:
phaichayon
2026-06-25 13:09:21 +07:00
parent c2a74b6764
commit 65dd0e2e56
27 changed files with 1583 additions and 179 deletions

View File

@@ -457,6 +457,14 @@ async function assertOpportunityBelongsToOrganization(id: string, organizationId
return opportunity;
}
function assertOpportunityOpenForQuotation(
opportunity: Awaited<ReturnType<typeof assertOpportunityBelongsToOrganization>>
) {
if ((opportunity.outcomeStatus ?? 'open') !== 'open') {
throw new AuthError('Closed opportunities cannot create quotations', 400);
}
}
async function assertQuotationBelongsToOrganization(
id: string,
organizationId: string,
@@ -1292,6 +1300,9 @@ export async function createQuotation(
const opportunity = payload.opportunityId
? await assertOpportunityBelongsToOrganization(payload.opportunityId, organizationId)
: null;
if (opportunity) {
assertOpportunityOpenForQuotation(opportunity);
}
const documentCode = await generateNextDocumentCode({
organizationId,
documentType: 'quotation',
@@ -2345,4 +2356,3 @@ export async function listCustomerQuotationRelations(
updatedAt: row.updatedAt.toISOString()
}));
}