From f248c5889fdb5999ad3697c1d3513272876f37c6 Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Mon, 24 Nov 2025 10:28:09 +0700 Subject: [PATCH] fix: improve record comparison by normalizing whitespace in invoice IDs during database sync --- src/controllers/syncController.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/controllers/syncController.ts b/src/controllers/syncController.ts index fdb7e8c..5c25332 100644 --- a/src/controllers/syncController.ts +++ b/src/controllers/syncController.ts @@ -143,10 +143,19 @@ async function processDatabaseSync(database: any) { }); for (const op of ops) { + const removeSpace = (string: string) => { + return string + .replace( + /[\s\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u3000\uFEFF]/g, + " " + ) + .replace(/\s+/g, " ") + .trim(); + }; const existData = existingRecords.find( (record) => - JSON.stringify(record.c_invoice_id) === - JSON.stringify(op.c_invoice_id) + removeSpace(JSON.stringify(record.c_invoice_id)) === + removeSpace(JSON.stringify(op.c_invoice_id)) ); const existingId = existData ? existData.id : null; if (existingId) {