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:
@@ -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[] }> {
|
||||
|
||||
Reference in New Issue
Block a user