fix: keep birthdays and show Shamsi dates
Imported customers keep their birthday, and assistant text plus remaining calendars use the Jalali date. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { parseBirthDate } from '../common/excel';
|
||||
import * as path from 'node:path';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import type {
|
||||
@@ -268,6 +269,7 @@ export class LeadsService {
|
||||
city?: string | null;
|
||||
region?: string | null;
|
||||
instagram?: string | null;
|
||||
birthDate?: string | null;
|
||||
addresses?: string[];
|
||||
trade?: string | null;
|
||||
source?: string | null;
|
||||
@@ -314,6 +316,7 @@ export class LeadsService {
|
||||
city: emptyToNull(dto.city),
|
||||
region: emptyToNull(dto.region),
|
||||
instagram: emptyToNull(dto.instagram),
|
||||
birthDate: parseBirthDate(dto.birthDate),
|
||||
addresses: toJsonAddresses(dto.addresses),
|
||||
trade: emptyToNull(dto.trade),
|
||||
source: emptyToNull(dto.source),
|
||||
@@ -398,6 +401,9 @@ export class LeadsService {
|
||||
...(dto.instagram !== undefined
|
||||
? { instagram: emptyToNull(dto.instagram as string) }
|
||||
: {}),
|
||||
...(dto.birthDate !== undefined
|
||||
? { birthDate: parseBirthDate(dto.birthDate as string | null) }
|
||||
: {}),
|
||||
...(dto.addresses !== undefined
|
||||
? {
|
||||
addresses: toJsonAddresses(
|
||||
@@ -802,6 +808,7 @@ export class LeadsService {
|
||||
mobile: lead.mobile,
|
||||
phone: lead.phone,
|
||||
instagram: lead.instagram,
|
||||
birthDate: lead.birthDate,
|
||||
addresses: toJsonAddresses(asAddresses(lead.addresses)),
|
||||
notes: [
|
||||
lead.notes,
|
||||
@@ -819,6 +826,11 @@ export class LeadsService {
|
||||
},
|
||||
});
|
||||
createdPerson = true;
|
||||
} else if (!person.birthDate && lead.birthDate) {
|
||||
await this.prisma.person.update({
|
||||
where: { id: person.id },
|
||||
data: { birthDate: lead.birthDate },
|
||||
});
|
||||
}
|
||||
|
||||
const convertedStage = await this.prisma.leadStage.findFirst({
|
||||
@@ -985,6 +997,7 @@ export class LeadsService {
|
||||
address2?: string;
|
||||
homeAddress?: string;
|
||||
instagram?: string;
|
||||
birthDate?: string;
|
||||
registeredAt?: string;
|
||||
trade?: string;
|
||||
source?: string;
|
||||
@@ -996,11 +1009,20 @@ export class LeadsService {
|
||||
const title = String(row.title ?? row.contactName ?? '').trim();
|
||||
if (!mobile || !title) return 'error';
|
||||
|
||||
const birthDate = parseBirthDate(row.birthDate);
|
||||
const existingLead = await this.prisma.lead.findFirst({
|
||||
where: { organizationId, mobile },
|
||||
select: { id: true },
|
||||
});
|
||||
if (existingLead) return 'duplicate';
|
||||
if (existingLead) {
|
||||
if (birthDate) {
|
||||
await this.prisma.lead.updateMany({
|
||||
where: { id: existingLead.id, birthDate: null },
|
||||
data: { birthDate },
|
||||
});
|
||||
}
|
||||
return 'duplicate';
|
||||
}
|
||||
|
||||
const existingPerson = await this.prisma.person.findFirst({
|
||||
where: {
|
||||
@@ -1009,7 +1031,15 @@ export class LeadsService {
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
if (existingPerson) return 'duplicate';
|
||||
if (existingPerson) {
|
||||
if (birthDate) {
|
||||
await this.prisma.person.updateMany({
|
||||
where: { id: existingPerson.id, birthDate: null },
|
||||
data: { birthDate },
|
||||
});
|
||||
}
|
||||
return 'duplicate';
|
||||
}
|
||||
|
||||
try {
|
||||
const registeredAt = row.registeredAt ? new Date(row.registeredAt) : null;
|
||||
@@ -1023,6 +1053,7 @@ export class LeadsService {
|
||||
city: emptyToNull(row.city),
|
||||
region: emptyToNull(row.region),
|
||||
instagram: emptyToNull(row.instagram),
|
||||
birthDate,
|
||||
addresses: toJsonAddresses(
|
||||
collectAddresses(row.address, row.address2, row.homeAddress),
|
||||
),
|
||||
@@ -1101,6 +1132,7 @@ export class LeadsService {
|
||||
city: row.city,
|
||||
region: row.region,
|
||||
instagram: row.instagram,
|
||||
birthDate: row.birthDate?.toISOString() ?? null,
|
||||
addresses: asAddresses(row.addresses),
|
||||
trade: row.trade,
|
||||
source: row.source,
|
||||
|
||||
Reference in New Issue
Block a user