Add lead funnel, stage conversion, and dwell reports to the report builder.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-18 17:29:58 +03:30
co-authored by Cursor
parent 2788103488
commit 968252ec2f
6 changed files with 944 additions and 27 deletions
+56 -3
View File
@@ -515,7 +515,10 @@ export class LeadsService {
include: leadInclude,
});
await this.addEvent(actor, row.id, 'created', 'لید ایجاد شد', null);
await this.addEvent(actor, row.id, 'created', 'لید ایجاد شد', null, {
stageId: row.stageId,
stageName: row.stage.name,
});
if (assigneeId) {
await this.addEvent(
actor,
@@ -675,6 +678,13 @@ export class LeadsService {
id,
'stage_changed',
`وضعیت به «${row.stage.name}» تغییر کرد`,
null,
{
fromStageId: existing.stageId,
fromStageName: existing.stage?.name ?? null,
toStageId: row.stageId,
toStageName: row.stage.name,
},
);
this.gameEvent(actor, 'LEAD_STAGE_CHANGED', row, {
eventKey: `${id}:${row.stageId}`,
@@ -732,6 +742,13 @@ export class LeadsService {
id,
'stage_changed',
`به مرحله «${stage.name}» منتقل شد`,
null,
{
fromStageId: before.stageId,
fromStageName: before.stage?.name ?? null,
toStageId: stageId,
toStageName: stage.name,
},
);
this.gameEvent(actor, 'LEAD_STAGE_CHANGED', row, {
eventKey: `${id}:${stageId}`,
@@ -790,6 +807,18 @@ export class LeadsService {
where: { id: stageId, organizationId: actor.organizationId },
});
if (!stage) throw new NotFoundException('مرحله پیدا نشد');
const beforeRows = await this.prisma.lead.findMany({
where: {
organizationId: actor.organizationId,
id: { in: leadIds },
archivedAt: null,
},
select: {
id: true,
stageId: true,
stage: { select: { name: true } },
},
});
const result = await this.prisma.lead.updateMany({
where: {
organizationId: actor.organizationId,
@@ -798,12 +827,20 @@ export class LeadsService {
},
data: { stageId },
});
for (const leadId of leadIds) {
for (const lead of beforeRows) {
if (lead.stageId === stageId) continue;
await this.addEvent(
actor,
leadId,
lead.id,
'stage_changed',
`وضعیت گروهی به «${stage.name}»`,
null,
{
fromStageId: lead.stageId,
fromStageName: lead.stage.name,
toStageId: stageId,
toStageName: stage.name,
},
);
}
return result.count;
@@ -1118,6 +1155,22 @@ export class LeadsService {
include: leadInclude,
});
if (convertedStage && convertedStage.id !== lead.stageId) {
await this.addEvent(
actor,
id,
'stage_changed',
`وضعیت به «${convertedStage.name}» تغییر کرد`,
null,
{
fromStageId: lead.stageId,
fromStageName: lead.stage?.name ?? null,
toStageId: convertedStage.id,
toStageName: convertedStage.name,
},
);
}
await this.addEvent(
actor,
id,