From 86e9ee6c2c907ea6085e80d73f8062cd69971c25 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Tue, 20 Oct 2026 12:26:20 +0330 Subject: [PATCH] fix: treat Tahesab no-records as an empty customer list instead of a 502 Listing all customers no longer fails on the final empty code range, and importing a missing code no longer creates a placeholder person. --- .../tahesab/person-link.service.ts | 8 ++++++- .../integrations/tahesab/tahesab-methods.ts | 22 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/api/src/integrations/tahesab/person-link.service.ts b/apps/api/src/integrations/tahesab/person-link.service.ts index 99ec921..efcc169 100644 --- a/apps/api/src/integrations/tahesab/person-link.service.ts +++ b/apps/api/src/integrations/tahesab/person-link.service.ts @@ -507,7 +507,13 @@ export class TahesabPersonLinkService { dto.moshtariCode, dto.moshtariCode, ); - row = (asMoshtariList(raw)[0] ?? {}) as Record; + const found = asMoshtariList(raw)[0]; + if (!found) { + throw new NotFoundException( + `مشتری با کد ${dto.moshtariCode} در ته‌حساب یافت نشد.`, + ); + } + row = found as Record; } const name = pickName(row) || `مشتری ته‌حساب ${dto.moshtariCode}`; const tel = pickTel(row); diff --git a/apps/api/src/integrations/tahesab/tahesab-methods.ts b/apps/api/src/integrations/tahesab/tahesab-methods.ts index be673b4..a770b3e 100644 --- a/apps/api/src/integrations/tahesab/tahesab-methods.ts +++ b/apps/api/src/integrations/tahesab/tahesab-methods.ts @@ -176,6 +176,9 @@ export function normalizeMandehResponse(raw: unknown): NormalizedAssets { }; } +/** ته‌حساب برای بازه/جستجوی بدون نتیجه به‌جای لیست خالی خطای «هیچ رکوردی یافت نشد» می‌دهد */ +const NO_RECORDS = { emptyResultOnError: /رکوردی یافت نشد/i }; + export class TahesabApi { constructor( private readonly http: TahesabHttpClient, @@ -307,15 +310,30 @@ export class TahesabApi { [fromCode, toCode], 'POST', opts?.timeoutMs, + NO_RECORDS, ); } doListMoshtariByPhone(phone: string | number) { - return this.call('DoListMoshtari-ByPhone', 'DoListMoshtari', [phone]); + return this.call( + 'DoListMoshtari-ByPhone', + 'DoListMoshtari', + [phone], + undefined, + undefined, + NO_RECORDS, + ); } doListMoshtariByName(name: string) { - return this.call('DoListMoshtari-ByName', 'DoListMoshtari', [name]); + return this.call( + 'DoListMoshtari-ByName', + 'DoListMoshtari', + [name], + undefined, + undefined, + NO_RECORDS, + ); } /** body key حساس به حروف کوچک مثل همکار */