diff --git a/src/controllers/04-service-controller.ts b/src/controllers/04-service-controller.ts index 0934238..6c0cf4d 100644 --- a/src/controllers/04-service-controller.ts +++ b/src/controllers/04-service-controller.ts @@ -308,6 +308,18 @@ export class ServiceController extends Controller { await permissionCheck(req.user, productGroup.registeredBranch); + if (body.installments && body.work) { + for (let i = 0; i < body.installments; i++) { + if (!body.work.some((w) => w.product.some((p) => p.installmentNo === i + 1))) { + throw new HttpError( + HttpStatus.BAD_REQUEST, + "Installments validate failed.", + "installmentsValidateFailed", + ); + } + } + } + const record = await prisma.$transaction( async (tx) => { const branch = productGroup.registeredBranch; @@ -419,6 +431,18 @@ export class ServiceController extends Controller { await permissionCheck(req.user, productGroup.registeredBranch); } + if (body.installments && body.work) { + for (let i = 0; i < body.installments; i++) { + if (!body.work.some((w) => w.product.some((p) => p.installmentNo === i + 1))) { + throw new HttpError( + HttpStatus.BAD_REQUEST, + "Installments validate failed.", + "installmentsValidateFailed", + ); + } + } + } + const record = await prisma.$transaction(async (tx) => { if (payload.workflowId === "") payload.workflowId = undefined;