Relabel false Didar contact sources as Excel and stop exporting CRM ids as Didar codes.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -25,7 +25,7 @@ import {
|
||||
import { CompaniesService } from './companies.service';
|
||||
import { PeopleService } from './people.service';
|
||||
import { normalizeEmail, normalizePhone } from './normalize';
|
||||
import { normalizePersonImportSource } from './person-source';
|
||||
import { resolveDidarSourceRef } from './person-source';
|
||||
import {
|
||||
CustomerGroupsService,
|
||||
splitGroupNames,
|
||||
@@ -397,7 +397,10 @@ export class ContactsExcelService {
|
||||
const groupText = groupNamesText(p.groups, extra.group);
|
||||
return {
|
||||
_type: 'Contact',
|
||||
didarId: extra.didarId ?? p.id,
|
||||
didarId:
|
||||
p.importSource === 'didar'
|
||||
? p.sourceRef || extra.didarId || ''
|
||||
: '',
|
||||
customerCode: extra.customerCode ?? '',
|
||||
title: extra.title ?? '',
|
||||
firstName: p.firstName,
|
||||
@@ -586,14 +589,13 @@ export class ContactsExcelService {
|
||||
})();
|
||||
|
||||
try {
|
||||
const didarId = customFields.didarId?.trim() || '';
|
||||
const didarId = resolveDidarSourceRef(customFields.didarId);
|
||||
const customerCode = customFields.customerCode?.trim() || '';
|
||||
const sourceCol = customFields.source?.trim() || '';
|
||||
const importSource = didarId
|
||||
? 'didar'
|
||||
: sourceCol
|
||||
? normalizePersonImportSource(sourceCol)
|
||||
: 'excel';
|
||||
// ایمپورت اکسل فقط با کد مبدأ واقعی دیدار برچسب «دیدار» میگیرد؛
|
||||
// cuid داخلی یا ستون «منبع اطلاعات» باعث دیدار شدن نمیشود.
|
||||
if (didarId) customFields.didarId = didarId;
|
||||
else delete customFields.didarId;
|
||||
const importSource = didarId ? 'didar' : 'excel';
|
||||
const sourceRef = didarId || customerCode || null;
|
||||
const groupIds = await this.groups.idsForNames(actor.organizationId, groupNames);
|
||||
|
||||
@@ -691,7 +693,7 @@ export class ContactsExcelService {
|
||||
else ownerMissing = true;
|
||||
}
|
||||
|
||||
const didarId = row.didarId?.trim() || '';
|
||||
const didarId = resolveDidarSourceRef(row.didarId) || '';
|
||||
const customFields: Record<string, string> = {};
|
||||
const visibility = row.visibility?.trim();
|
||||
if (visibility) customFields.visibility = visibility;
|
||||
@@ -800,7 +802,7 @@ export class ContactsExcelService {
|
||||
didarId?: string,
|
||||
phone?: string,
|
||||
): Promise<string> {
|
||||
const ref = didarId?.trim() || '';
|
||||
const ref = resolveDidarSourceRef(didarId) || '';
|
||||
if (ref) {
|
||||
const byRef = await this.prisma.company.findFirst({
|
||||
where: {
|
||||
|
||||
@@ -29,6 +29,20 @@ export function personImportSourceLabel(source: string): string {
|
||||
return source || PERSON_IMPORT_SOURCE_LABELS.manual;
|
||||
}
|
||||
|
||||
/**
|
||||
* کد مبدأ واقعی دیدار برای برچسبزدن منبع.
|
||||
* cuid داخلی مونتاکت و مقادیر توخالی را دیدار حساب نکن
|
||||
* (باگ قبلی: خروجی اکسل id داخلی را در ستون کد دیدار میگذاشت).
|
||||
*/
|
||||
export function resolveDidarSourceRef(raw?: string | null): string | null {
|
||||
const v = String(raw ?? '').trim();
|
||||
if (!v) return null;
|
||||
if (/^(0+|-+|\.+|n\/?a|null|undefined|none)$/i.test(v)) return null;
|
||||
// Prisma/cuid داخلی (~25 کاراکتر با پیشوند c)
|
||||
if (/^c[a-z0-9]{20,32}$/i.test(v)) return null;
|
||||
return v;
|
||||
}
|
||||
|
||||
type SourceSnapshot = {
|
||||
importSource?: string | null;
|
||||
sourceRef?: string | null;
|
||||
@@ -40,8 +54,10 @@ type SourceSnapshot = {
|
||||
function didarIdFrom(customFields: unknown): string | null {
|
||||
if (!customFields || typeof customFields !== 'object') return null;
|
||||
const raw = (customFields as Record<string, unknown>).didarId;
|
||||
if (typeof raw === 'number' && Number.isFinite(raw)) return String(raw);
|
||||
if (typeof raw === 'string' && raw.trim()) return raw.trim();
|
||||
if (typeof raw === 'number' && Number.isFinite(raw)) {
|
||||
return resolveDidarSourceRef(String(raw));
|
||||
}
|
||||
if (typeof raw === 'string') return resolveDidarSourceRef(raw);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,10 +61,11 @@ function parseTags(raw?: string) {
|
||||
.slice(0, 20);
|
||||
}
|
||||
|
||||
/** کدهای دیدار: «0» و خالی یعنی بدون کد */
|
||||
/** کدهای دیدار: «0»، خالی، و cuid داخلی یعنی بدون کد مبدأ واقعی */
|
||||
function cleanCode(raw?: string): string {
|
||||
const v = toAsciiDigits(raw ?? '').trim();
|
||||
if (!v || /^0+$/.test(v)) return '';
|
||||
if (/^c[a-z0-9]{20,32}$/i.test(v)) return '';
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -126,9 +127,18 @@ export class DealsExcelService {
|
||||
lastName: true,
|
||||
mobile: true,
|
||||
sourceRef: true,
|
||||
importSource: true,
|
||||
},
|
||||
},
|
||||
company: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
phone: true,
|
||||
sourceRef: true,
|
||||
importSource: true,
|
||||
},
|
||||
},
|
||||
company: { select: { id: true, name: true, phone: true, sourceRef: true } },
|
||||
owner: { select: { fullName: true } },
|
||||
createdBy: { select: { fullName: true } },
|
||||
pipeline: { select: { name: true } },
|
||||
@@ -157,7 +167,7 @@ export class DealsExcelService {
|
||||
const extra = asCustomFields(row.customFields);
|
||||
const base: Record<string, string | number | null> = {
|
||||
_type: 'Deal',
|
||||
didarId: row.sourceRef ?? row.id,
|
||||
didarId: row.importSource === 'didar' ? row.sourceRef || '' : '',
|
||||
code: row.code ?? '',
|
||||
title: row.title,
|
||||
amount: row.amount == null ? 0 : Number(row.amount),
|
||||
@@ -181,10 +191,12 @@ export class DealsExcelService {
|
||||
stageName: row.stage.name,
|
||||
personFirstName: row.person?.firstName ?? '',
|
||||
personName: row.person?.lastName ?? '',
|
||||
personCode: row.person ? (row.person.sourceRef ?? row.person.id) : '',
|
||||
personCode:
|
||||
row.person?.importSource === 'didar' ? row.person.sourceRef || '' : '',
|
||||
personMobile: row.person?.mobile ?? '',
|
||||
companyName: row.company?.name ?? '',
|
||||
companyCode: row.company ? (row.company.sourceRef ?? row.company.id) : '',
|
||||
companyCode:
|
||||
row.company?.importSource === 'didar' ? row.company.sourceRef || '' : '',
|
||||
companyPhone: row.company?.phone ?? '',
|
||||
};
|
||||
for (const d of defs) {
|
||||
|
||||
Reference in New Issue
Block a user