diff --git a/apps/api/prisma/migrations/20261119120000_activity_experience/migration.sql b/apps/api/prisma/migrations/20261119120000_activity_experience/migration.sql new file mode 100644 index 0000000..e873acc --- /dev/null +++ b/apps/api/prisma/migrations/20261119120000_activity_experience/migration.sql @@ -0,0 +1,11 @@ +-- AlterTable +ALTER TABLE "Lead" ADD COLUMN "activityExperience" TEXT; + +-- AlterTable +ALTER TABLE "Person" ADD COLUMN "activityExperience" TEXT; + +-- CreateIndex +CREATE INDEX "Lead_organizationId_activityExperience_idx" ON "Lead"("organizationId", "activityExperience"); + +-- CreateIndex +CREATE INDEX "Person_organizationId_activityExperience_idx" ON "Person"("organizationId", "activityExperience"); diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index ad4d6f7..2e21b3a 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -656,6 +656,8 @@ model Person { birthDate DateTime? /// نام معرف referrer String? + /// سابقه فعالیت (ندارم | 1 الی 2 سال | 2 الی 5 سال | بیش از 5 سال) + activityExperience String? /// لیست آدرس‌ها (JSON array of strings) addresses Json @default("[]") notes String? @@ -710,6 +712,7 @@ model Person { @@index([ownerId]) @@index([loyaltyTierId]) @@index([organizationId, discLabel]) + @@index([organizationId, activityExperience]) } model Pipeline { @@ -3158,6 +3161,8 @@ model Lead { /// صنف trade String? source String? + /// سابقه فعالیت (ندارم | 1 الی 2 سال | 2 الی 5 سال | بیش از 5 سال) + activityExperience String? notes String? /// لوگوی فروشگاه / شرکت logoStorageKey String? @@ -3195,6 +3200,7 @@ model Lead { @@index([organizationId, city]) @@index([organizationId, trade]) @@index([organizationId, source]) + @@index([organizationId, activityExperience]) } model LeadEvent { diff --git a/apps/api/src/contacts/dto.ts b/apps/api/src/contacts/dto.ts index 221d9d1..5dd7f71 100644 --- a/apps/api/src/contacts/dto.ts +++ b/apps/api/src/contacts/dto.ts @@ -100,6 +100,12 @@ export class ListQueryDto { @IsString() @MaxLength(2000) groupId?: string; + + /** فیلتر سابقه فعالیت؛ چندتایی با کاما */ + @IsOptional() + @IsString() + @MaxLength(400) + activityExperience?: string; } class CompanyExtraFieldsDto { @@ -360,6 +366,11 @@ export class CreatePersonDto { @MaxLength(120) referrer?: string; + @IsOptional() + @IsString() + @MaxLength(80) + activityExperience?: string | null; + @IsOptional() @IsArray() @IsString({ each: true }) @@ -486,6 +497,11 @@ export class UpdatePersonDto { @MaxLength(120) referrer?: string; + @IsOptional() + @IsString() + @MaxLength(80) + activityExperience?: string | null; + @IsOptional() @IsArray() @IsString({ each: true }) diff --git a/apps/api/src/contacts/people.controller.ts b/apps/api/src/contacts/people.controller.ts index b015349..6f67f18 100644 --- a/apps/api/src/contacts/people.controller.ts +++ b/apps/api/src/contacts/people.controller.ts @@ -63,6 +63,7 @@ export class PeopleController { hasMobile, disc: query.disc, groupId: query.groupId, + activityExperience: query.activityExperience, }, ); } @@ -81,6 +82,7 @@ export class PeopleController { hasMobile, disc: query.disc, groupId: query.groupId, + activityExperience: query.activityExperience, }); } diff --git a/apps/api/src/contacts/people.service.ts b/apps/api/src/contacts/people.service.ts index a82fd00..0d3924c 100644 --- a/apps/api/src/contacts/people.service.ts +++ b/apps/api/src/contacts/people.service.ts @@ -23,6 +23,7 @@ import { PERSON_MOODS, applyPersonGenderTitle, canViewAllRecords, + normalizeActivityExperience, splitPersonHonorific, } from '@mento/shared'; import { Prisma } from '@prisma/client'; @@ -102,6 +103,7 @@ type PersonRow = { instagram: string | null; birthDate: Date | null; referrer: string | null; + activityExperience: string | null; addresses: unknown; notes: string | null; mood: PersonMood; @@ -174,6 +176,7 @@ export class PeopleService implements OnModuleInit { hasMobile?: boolean; disc?: string; groupId?: string; + activityExperience?: string; }, ): Prisma.PersonWhereInput { const sources = [...new Set(splitCsv(opts?.importSource).map(normalizePersonImportSource))]; @@ -181,6 +184,7 @@ export class PeopleService implements OnModuleInit { (PERSON_MOODS as readonly string[]).includes(m), ); const groupIds = splitCsv(opts?.groupId); + const experiences = splitCsv(opts?.activityExperience); const search = buildSearchWhere(q, (t) => [ { firstName: ci(t) }, { lastName: ci(t) }, @@ -231,6 +235,9 @@ export class PeopleService implements OnModuleInit { if (sources.length) { facets.push({ importSource: { in: sources } }); } + if (experiences.length) { + facets.push({ activityExperience: { in: experiences } }); + } if (facets.length === 1) and.push(facets[0]!); else if (facets.length > 1) and.push({ OR: facets }); return { @@ -258,6 +265,7 @@ export class PeopleService implements OnModuleInit { hasMobile?: boolean; disc?: string; groupId?: string; + activityExperience?: string; }, ): Promise> { const seeDisc = await this.behaviorAccess.canView(actor); @@ -296,6 +304,7 @@ export class PeopleService implements OnModuleInit { hasMobile?: boolean; disc?: string; groupId?: string; + activityExperience?: string; }, max = FILTERED_IDS_MAX, ): Promise { @@ -475,6 +484,9 @@ export class PeopleService implements OnModuleInit { instagram: emptyToNull(dto.instagram), birthDate: parseBirthDate(dto.birthDate), referrer: emptyToNull(dto.referrer), + activityExperience: + normalizeActivityExperience(dto.activityExperience) ?? + emptyToNull(dto.activityExperience), addresses: toJsonAddresses(dto.addresses), notes: emptyToNull(dto.notes), mood: dto.mood ?? 'newcomer', @@ -587,6 +599,11 @@ export class PeopleService implements OnModuleInit { if ('instagram' in dto) data.instagram = emptyToNull(dto.instagram); if ('birthDate' in dto) data.birthDate = parseBirthDate(dto.birthDate); if ('referrer' in dto) data.referrer = emptyToNull(dto.referrer); + if ('activityExperience' in dto) { + data.activityExperience = + normalizeActivityExperience(dto.activityExperience) ?? + emptyToNull(dto.activityExperience); + } if ('addresses' in dto) data.addresses = toJsonAddresses(dto.addresses); if ('notes' in dto) data.notes = emptyToNull(dto.notes); if (dto.mood !== undefined) data.mood = dto.mood; @@ -1022,6 +1039,7 @@ export class PeopleService implements OnModuleInit { instagram: row.instagram, birthDate: row.birthDate?.toISOString() ?? null, referrer: row.referrer, + activityExperience: row.activityExperience, addresses: (() => { const fromCol = asAddresses(row.addresses); if (fromCol.length) return fromCol; diff --git a/apps/api/src/lead-forms/dto.ts b/apps/api/src/lead-forms/dto.ts index 853c0a7..2644253 100644 --- a/apps/api/src/lead-forms/dto.ts +++ b/apps/api/src/lead-forms/dto.ts @@ -30,9 +30,11 @@ const MAP_TO = [ 'lead.city', 'lead.region', 'lead.trade', + 'lead.activityExperience', 'lead.notes', 'lead.source', 'lead.gender', + 'person.activityExperience', 'person.gender', 'notes', 'custom', diff --git a/apps/api/src/lead-forms/lead-forms.service.ts b/apps/api/src/lead-forms/lead-forms.service.ts index 7e4ebd5..874a41a 100644 --- a/apps/api/src/lead-forms/lead-forms.service.ts +++ b/apps/api/src/lead-forms/lead-forms.service.ts @@ -13,7 +13,12 @@ import type { SubmitLeadFormResponse, UpdateLeadFormRequest, } from '@mento/shared'; -import { isGenderQuestionLabel, parsePersonGenderAnswer } from '@mento/shared'; +import { + isActivityExperienceLabel, + isGenderQuestionLabel, + normalizeActivityExperience, + parsePersonGenderAnswer, +} from '@mento/shared'; import { Prisma } from '@prisma/client'; import { PrismaService } from '../prisma/prisma.service'; import { LocalFileStorage } from '../storage/local-file.storage'; @@ -569,6 +574,9 @@ export class LeadFormsService { region: emptyToNull(mapped.region) ?? existingLead.region, trade: emptyToNull(mapped.trade) ?? existingLead.trade, source: source ?? existingLead.source, + activityExperience: + emptyToNull(mapped.activityExperience) ?? + existingLead.activityExperience, notes: emptyToNull(mapped.notes) ?? existingLead.notes, ...(mapped.gender ? { gender: mapped.gender } : {}), assigneeId: existingLead.assigneeId ?? assigneeId, @@ -620,6 +628,7 @@ export class LeadFormsService { region: emptyToNull(mapped.region), trade: emptyToNull(mapped.trade), source, + activityExperience: emptyToNull(mapped.activityExperience), notes: emptyToNull(mapped.notes), gender: mapped.gender ?? 'none', stageId, @@ -684,6 +693,8 @@ export class LeadFormsService { phone: phone ?? existing.phone, position: emptyToNull(mapped.position) ?? existing.position, notes: emptyToNull(mapped.notes) ?? existing.notes, + activityExperience: + emptyToNull(mapped.activityExperience) ?? existing.activityExperience, ...(mapped.gender ? { gender: mapped.gender } : {}), ownerId: existing.ownerId ?? ownerId, }, @@ -701,6 +712,7 @@ export class LeadFormsService { phone, position: emptyToNull(mapped.position), notes: emptyToNull(mapped.notes), + activityExperience: emptyToNull(mapped.activityExperience), gender: mapped.gender ?? 'none', ownerId, }, @@ -964,6 +976,7 @@ type MappedValues = { city?: string; region?: string; trade?: string; + activityExperience?: string; leadSource?: string; gender?: 'male' | 'female' | 'none'; }; @@ -995,6 +1008,15 @@ function mapValues( if (gender) mapped.gender = gender; continue; } + if ( + field.mapTo === 'lead.activityExperience' || + field.mapTo === 'person.activityExperience' || + isActivityExperienceLabel(field.label) + ) { + mapped.activityExperience = + normalizeActivityExperience(raw) ?? raw; + continue; + } switch (field.mapTo) { case 'person.fullName': { const parts = raw.split(/\s+/).filter(Boolean); @@ -1048,6 +1070,11 @@ function mapValues( case 'lead.trade': mapped.trade = raw; break; + case 'lead.activityExperience': + case 'person.activityExperience': + mapped.activityExperience = + normalizeActivityExperience(raw) ?? raw; + break; case 'lead.notes': mapped.notes = raw; break; @@ -1118,7 +1145,9 @@ function collectExtras( for (const field of fields) { if (field.fieldType === 'heading' || field.mapTo !== 'custom') continue; const raw = (values?.[field.key] ?? '').toString().trim(); - if (!raw || (isGenderQuestionLabel(field.label) && parsePersonGenderAnswer(raw))) continue; + if (!raw) continue; + if (isGenderQuestionLabel(field.label) && parsePersonGenderAnswer(raw)) continue; + if (isActivityExperienceLabel(field.label)) continue; lines.push(`${field.label}: ${raw}`); } return lines.join('\n'); diff --git a/apps/api/src/leads/dto.ts b/apps/api/src/leads/dto.ts index 0255333..9404975 100644 --- a/apps/api/src/leads/dto.ts +++ b/apps/api/src/leads/dto.ts @@ -37,6 +37,7 @@ export class CreateLeadDto { @IsOptional() @IsArray() @IsString({ each: true }) addresses?: string[]; @IsOptional() @IsString() trade?: string; @IsOptional() @IsString() source?: string; + @IsOptional() @IsString() activityExperience?: string | null; @IsOptional() @IsString() notes?: string; @IsOptional() @IsNumber() estimatedValue?: number; @IsOptional() @IsString() stageId?: string; @@ -60,6 +61,7 @@ export class UpdateLeadDto { @IsOptional() @IsArray() @IsString({ each: true }) addresses?: string[]; @IsOptional() @IsString() trade?: string | null; @IsOptional() @IsString() source?: string | null; + @IsOptional() @IsString() activityExperience?: string | null; @IsOptional() @IsString() notes?: string | null; @IsOptional() @IsNumber() estimatedValue?: number | null; @IsOptional() @IsString() stageId?: string; diff --git a/apps/api/src/leads/leads.controller.ts b/apps/api/src/leads/leads.controller.ts index 5a86742..a941c50 100644 --- a/apps/api/src/leads/leads.controller.ts +++ b/apps/api/src/leads/leads.controller.ts @@ -249,6 +249,7 @@ export class LeadsController { @Query('region') region?: string, @Query('trade') trade?: string, @Query('source') source?: string, + @Query('activityExperience') activityExperience?: string, @Query('unassigned') unassigned?: string, @Query('archived') archived?: string, @Query('converted') converted?: string, @@ -265,6 +266,7 @@ export class LeadsController { region, trade, source, + activityExperience, unassigned: unassigned === '1' || unassigned === 'true', archived: archived === '1' || archived === 'true', converted: converted === '1' || converted === 'true', @@ -287,6 +289,7 @@ export class LeadsController { @Query('region') region?: string, @Query('trade') trade?: string, @Query('source') source?: string, + @Query('activityExperience') activityExperience?: string, @Query('unassigned') unassigned?: string, @Query('archived') archived?: string, @Query('converted') converted?: string, @@ -306,6 +309,7 @@ export class LeadsController { region, trade, source, + activityExperience, unassigned: unassigned === '1' || unassigned === 'true', archived: archived === '1' || archived === 'true', converted: converted === '1' || converted === 'true', diff --git a/apps/api/src/leads/leads.service.ts b/apps/api/src/leads/leads.service.ts index 3608033..d6480e1 100644 --- a/apps/api/src/leads/leads.service.ts +++ b/apps/api/src/leads/leads.service.ts @@ -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, diff --git a/apps/web/src/components/ContactsFilterPanel.vue b/apps/web/src/components/ContactsFilterPanel.vue index 80ec9b4..c7b477b 100644 --- a/apps/web/src/components/ContactsFilterPanel.vue +++ b/apps/web/src/components/ContactsFilterPanel.vue @@ -1,6 +1,7 @@