Files
CRM_Montzar/apps/api/src/contacts/person-source.ts
T

42 lines
1.2 KiB
TypeScript
Raw Normal View History

import {
PERSON_IMPORT_SOURCE_LABELS,
PERSON_IMPORT_SOURCES,
type PersonImportSource,
} from '@mento/shared';
export function normalizePersonImportSource(
raw?: string | null,
): PersonImportSource {
const v = String(raw ?? '')
.trim()
.toLowerCase();
if (!v) return 'manual';
if ((PERSON_IMPORT_SOURCES as readonly string[]).includes(v)) {
return v as PersonImportSource;
}
if (/دیدار|didar/.test(v)) return 'didar';
if (/ته.?حساب|tahesab|accounting/.test(v)) return 'tahesab';
if (/اکسل|excel|xlsx|csv/.test(v)) return 'excel';
if (/گوشی|phone|مخاطب|vcard|contact/.test(v)) return 'phone';
if (/لید|lead|فرم/.test(v)) return 'lead_form';
return 'other';
}
export function personImportSourceLabel(source: string): string {
if (source in PERSON_IMPORT_SOURCE_LABELS) {
return PERSON_IMPORT_SOURCE_LABELS[source as PersonImportSource];
}
return source || PERSON_IMPORT_SOURCE_LABELS.manual;
}
export function namesDiffer(
aFirst: string,
aLast: string,
bFirst: string,
bLast: string,
): boolean {
const a = `${aFirst} ${aLast}`.trim().replace(/\s+/g, ' ');
const b = `${bFirst} ${bLast}`.trim().replace(/\s+/g, ' ');
return Boolean(a && b && a !== b);
}