task-d.5.6
This commit is contained in:
@@ -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()
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user