- Rial wage and gram-debt arithmetic matched to the reference; order corrections keep debt in sync - Document confirm/un-confirm is a compare-and-swap (no double-applied cache under concurrency) - Settlement document and expert inputs validated (400 instead of 500) - Expert: edit / activate-deactivate own customers, adjust raw weights only - Made-to-order flow in the app, PreOrder.quantity migration - Order grids: customer column, sort keys; panel select search; pre-order quantity save - Rebuilt release artifacts Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { BadRequestException } from '@nestjs/common';
|
|
import { faToEn } from '../modules/customer-auth/digits';
|
|
|
|
/**
|
|
* PERS-03: the birth date both customer forms collect (legacy bulkCustomer
|
|
* `birth_date`, singleCustomer `birth_day`). DateInput sends the Gregorian
|
|
* 'YYYY-MM-DD' of the Jalali date picked; stored at UTC midnight, as the
|
|
* import stores legacy's. undefined = not sent (leave as is), '' = cleared.
|
|
*
|
|
* Shared by the admin customer forms and the sales expert's «ویرایش مشتری» in
|
|
* the app, so both read a date the same way.
|
|
*/
|
|
export function birthDateOrNull(raw: unknown): Date | null | undefined {
|
|
if (raw === undefined) return undefined;
|
|
if (raw === null || String(raw).trim() === '') return null;
|
|
const m = /^(\d{4})-(\d{1,2})-(\d{1,2})/.exec(String(raw).trim());
|
|
const d = m ? new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])) : null;
|
|
if (!d || d.getUTCMonth() !== +m![2] - 1 || d.getUTCFullYear() < 1900 || d > new Date()) {
|
|
throw new BadRequestException('تاریخ تولد معتبر نیست');
|
|
}
|
|
return d;
|
|
}
|
|
|
|
/**
|
|
* A national code as the operator typed it, digits normalised; empty -> null.
|
|
* The column is optional and unique (2026-10-07): an absent code is NULL,
|
|
* never the mobile or '' — two customers without one must not collide, and
|
|
* the column must only ever hold a national code.
|
|
*/
|
|
export function nationalCodeOrNull(raw: unknown): string | null {
|
|
return faToEn(String(raw ?? '').trim()) || null;
|
|
}
|