From 5fc4bbab6e49750ec579f523ae640ddbd9d410c1 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Mar 2025 14:30:05 +0700 Subject: [PATCH] fix: detect not work due to floating point --- src/controllers/05-quotation-controller.ts | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index e47a15c..111d78f 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -851,20 +851,18 @@ export class QuotationController extends Controller { finalPrice: 0, }, ); - const changed = list - ? record.productServiceList.some( - (lhs) => - !list?.find((rhs) => { - return ( - lhs.serviceId === rhs.serviceId && - lhs.workId === rhs.workId && - lhs.productId === rhs.productId && - lhs.discount === rhs.discount && - lhs.pricePerUnit === rhs.pricePerUnit - ); - }), - ) - : false; + const changed = list?.some((lhs) => { + const found = record.productServiceList.find((rhs) => { + return ( + lhs.serviceId === rhs.serviceId && + lhs.workId === rhs.workId && + lhs.productId === rhs.productId && + lhs.amount === rhs.amount && + precisionRound(lhs.pricePerUnit, 6) === precisionRound(rhs.pricePerUnit, 6) + ); + }); + return !found; + }); await Promise.all([ tx.service.updateMany({ where: { id: { in: ids.service }, status: Status.CREATED },