Add optional activity experience on leads and people with form mapping and filters.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-19 21:04:43 +03:30
co-authored by Cursor
parent e90f9f9538
commit a455ab71ab
19 changed files with 430 additions and 20 deletions
+44 -6
View File
@@ -20,7 +20,11 @@ import type {
PaginatedResponse,
} from '@mento/shared';
import { FILTERED_IDS_MAX } from '@mento/shared';
import { applyLeadGenderName, applyPersonGenderTitle } from '@mento/shared';
import {
applyLeadGenderName,
applyPersonGenderTitle,
normalizeActivityExperience,
} from '@mento/shared';
import { PrismaService } from '../prisma/prisma.service';
import { SmsGatewayService } from '../sms-billing/sms-gateway.service';
import { renderSmsText } from '../common/sms-text';
@@ -119,6 +123,7 @@ const boardLeadSelect = {
birthDate: true,
trade: true,
source: true,
activityExperience: true,
logoStorageKey: true,
estimatedValue: true,
stageId: true,
@@ -177,6 +182,7 @@ export class LeadsService {
region?: string;
trade?: string;
source?: string;
activityExperience?: string;
unassigned?: boolean;
archived?: boolean;
converted?: boolean;
@@ -196,6 +202,7 @@ export class LeadsService {
{ trade: ci(t) },
{ instagram: ci(t) },
{ source: ci(t) },
{ activityExperience: ci(t) },
]);
const and: Prisma.LeadWhereInput[] = [];
if (search) and.push(search);
@@ -222,6 +229,9 @@ export class LeadsService {
...(opts.source
? { source: { contains: opts.source, mode: 'insensitive' } }
: {}),
...(opts.activityExperience
? { activityExperience: opts.activityExperience }
: {}),
},
...(opts.unassigned ? [{ assigneeId: null }] : []),
...(opts.assigneeId && !opts.unassigned ? [{ assigneeId: opts.assigneeId }] : []),
@@ -288,6 +298,7 @@ export class LeadsService {
region?: string;
trade?: string;
source?: string;
activityExperience?: string;
unassigned?: boolean;
archived?: boolean;
converted?: boolean;
@@ -341,6 +352,7 @@ export class LeadsService {
region?: string;
trade?: string;
source?: string;
activityExperience?: string;
unassigned?: boolean;
archived?: boolean;
converted?: boolean;
@@ -492,6 +504,7 @@ export class LeadsService {
addresses?: string[];
trade?: string | null;
source?: string | null;
activityExperience?: string | null;
notes?: string | null;
estimatedValue?: number | null;
stageId?: string;
@@ -553,6 +566,9 @@ export class LeadsService {
addresses: toJsonAddresses(dto.addresses),
trade: emptyToNull(dto.trade),
source: emptyToNull(dto.source),
activityExperience:
normalizeActivityExperience(dto.activityExperience) ??
emptyToNull(dto.activityExperience),
notes: emptyToNull(dto.notes),
estimatedValue:
dto.estimatedValue != null
@@ -684,6 +700,13 @@ export class LeadsService {
...(dto.source !== undefined
? { source: emptyToNull(dto.source as string) }
: {}),
...(dto.activityExperience !== undefined
? {
activityExperience:
normalizeActivityExperience(dto.activityExperience as string | null) ??
emptyToNull(dto.activityExperience as string),
}
: {}),
...(dto.notes !== undefined
? { notes: emptyToNull(dto.notes as string) }
: {}),
@@ -1194,6 +1217,7 @@ export class LeadsService {
]
.filter(Boolean)
.join('\n'),
activityExperience: lead.activityExperience,
ownerId: lead.assigneeId ?? actor.userId,
createdAt: lead.createdAt,
importSource: 'lead_form',
@@ -1201,11 +1225,23 @@ export class LeadsService {
},
});
createdPerson = true;
} else if (!person.birthDate && lead.birthDate) {
await this.prisma.person.update({
where: { id: person.id },
data: { birthDate: lead.birthDate },
});
} else {
const personPatch: {
birthDate?: Date | null;
activityExperience?: string | null;
} = {};
if (!person.birthDate && lead.birthDate) {
personPatch.birthDate = lead.birthDate;
}
if (!person.activityExperience && lead.activityExperience) {
personPatch.activityExperience = lead.activityExperience;
}
if (Object.keys(personPatch).length) {
await this.prisma.person.update({
where: { id: person.id },
data: personPatch,
});
}
}
const convertedStage = await this.prisma.leadStage.findFirst({
@@ -1626,6 +1662,7 @@ export class LeadsService {
addresses: asAddresses(row.addresses),
trade: row.trade,
source: row.source,
activityExperience: row.activityExperience,
notes: row.notes,
estimatedValue:
row.estimatedValue != null ? Number(row.estimatedValue) : null,
@@ -1668,6 +1705,7 @@ export class LeadsService {
addresses: [],
trade: row.trade,
source: row.source,
activityExperience: row.activityExperience,
notes: null,
estimatedValue:
row.estimatedValue != null ? Number(row.estimatedValue) : null,