feat: check if installments is valid

This commit is contained in:
Methapon2001 2024-12-19 16:04:07 +07:00
parent 978eb0eee2
commit 6b4e13e94d

View file

@ -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;