From b1a1a83051a25185a0d970b8b6492cbd99a1a56d Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:24:38 +0700 Subject: [PATCH] fix: also take duplicate worker into account --- src/controllers/05-quotation-controller.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index 45a1114..37d77d2 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -869,7 +869,12 @@ export class QuotationActionController extends Controller { if (!quotation) throw relationError("Quotation"); if (ids.employee.length !== employee.length) throw relationError("Worker"); if (ids.productService.length !== productService.length) throw relationError("Product"); - if (quotation._count.worker + body.length > (quotation.workerMax || 0)) { + if ( + quotation._count.worker + + body.filter((lhs) => !quotation.worker.find((rhs) => rhs.employeeId === lhs.workerId)) + .length > + (quotation.workerMax || 0) + ) { if (body.length === 0) return; throw new HttpError( HttpStatus.PRECONDITION_FAILED,