feat: show the full work history and load every lead stage on the board

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-14 19:47:32 +03:30
co-authored by Cursor
parent 2cc81bb596
commit 831c682eb3
13 changed files with 669 additions and 66 deletions
+25 -21
View File
@@ -182,27 +182,31 @@ export class LeadsService {
async board(actor: Actor): Promise<LeadBoardColumnDto[]> {
const stages = await this.stages.list(actor.organizationId);
const boardStages = stages.filter((s) => s.showOnBoard);
const leads = await this.prisma.lead.findMany({
where: {
organizationId: actor.organizationId,
...leadAccessWhere(actor),
archivedAt: null,
stageId: { in: boardStages.map((s) => s.id) },
},
include: leadInclude,
orderBy: [{ stageId: 'asc' }, { position: 'asc' }, { updatedAt: 'desc' }],
take: 500,
});
const byStage = new Map<string, LeadDto[]>();
for (const s of boardStages) byStage.set(s.id, []);
for (const row of leads) {
const list = byStage.get(row.stageId);
if (list) list.push(this.toDto(row));
}
return boardStages.map((stage) => ({
stage,
leads: byStage.get(stage.id) ?? [],
}));
const whereBase = {
organizationId: actor.organizationId,
...leadAccessWhere(actor),
archivedAt: null,
};
const perColumn = 120;
return Promise.all(
boardStages.map(async (stage) => {
const where = { ...whereBase, stageId: stage.id };
const [total, rows] = await Promise.all([
this.prisma.lead.count({ where }),
this.prisma.lead.findMany({
where,
include: leadInclude,
orderBy: [{ position: 'asc' }, { updatedAt: 'desc' }],
take: perColumn,
}),
]);
return {
stage,
total,
leads: rows.map((row) => this.toDto(row)),
};
}),
);
}
async get(actor: Actor, id: string): Promise<LeadDto & { events: LeadEventDto[] }> {