Align DoListAsnad with Hamkar (4 args) and treat empty ERROR as [].
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,6 +12,16 @@ import {
|
||||
SanadBuilders,
|
||||
} from './tahesab-methods';
|
||||
|
||||
function normalizeShamsiYmd(input: string): string {
|
||||
const m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(input.trim());
|
||||
if (!m) {
|
||||
throw new BadRequestException(
|
||||
'تاریخ از/تا باید شمسی با قالب YYYY-MM-DD باشد.',
|
||||
);
|
||||
}
|
||||
return `${m[1]}-${m[2]!.padStart(2, '0')}-${m[3]!.padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function asAsnadList(raw: unknown): Array<Record<string, unknown>> {
|
||||
if (!raw) return [];
|
||||
if (Array.isArray(raw)) return raw as Array<Record<string, unknown>>;
|
||||
@@ -66,25 +76,27 @@ export class TahesabDocumentsService {
|
||||
to: string,
|
||||
connectionId?: string,
|
||||
) {
|
||||
if (!/^\d{4}-\d{1,2}-\d{1,2}$/.test(from) || !/^\d{4}-\d{1,2}-\d{1,2}$/.test(to)) {
|
||||
throw new BadRequestException(
|
||||
'تاریخ از/تا باید شمسی با قالب YYYY-MM-DD باشد.',
|
||||
);
|
||||
}
|
||||
const fromNorm = normalizeShamsiYmd(from);
|
||||
const toNorm = normalizeShamsiYmd(to);
|
||||
const resolvedId = await this.connections.resolveConnectionId(
|
||||
organizationId,
|
||||
connectionId,
|
||||
);
|
||||
const link = await this.requireLink(organizationId, personId, resolvedId);
|
||||
const { api } = await this.connections.getApi(organizationId, resolvedId);
|
||||
// Count_Last = سقف تعداد سند برگشتی (۰ در نمونه گاهی خالی برمیگرداند)
|
||||
const raw = await api.doListAsnad(500, link.moshtariCode, from, to);
|
||||
// Count_Last = -1 مثل همکار (مانده ردیفبهردیف / همه در بازه)
|
||||
const raw = await api.doListAsnad(
|
||||
-1,
|
||||
link.moshtariCode,
|
||||
fromNorm,
|
||||
toNorm,
|
||||
);
|
||||
const items = asAsnadList(raw);
|
||||
return {
|
||||
connectionId: resolvedId,
|
||||
moshtariCode: link.moshtariCode,
|
||||
from,
|
||||
to,
|
||||
from: fromNorm,
|
||||
to: toNorm,
|
||||
items,
|
||||
count: items.length,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user