feat: build dashboard lead funnel
This commit is contained in:
@@ -105,3 +105,48 @@ export const list = query({
|
||||
return await ctx.db.query("leads").order("desc").take(limit);
|
||||
},
|
||||
});
|
||||
|
||||
export const listFunnel = query({
|
||||
args: {
|
||||
limit: v.optional(v.number()),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const limit = normalizeListLimit(args.limit);
|
||||
const leads = await ctx.db.query("leads").order("desc").take(limit);
|
||||
|
||||
return await Promise.all(
|
||||
leads.map(async (lead) => {
|
||||
const outreach = await ctx.db
|
||||
.query("outreachRecords")
|
||||
.withIndex("by_leadId", (q) => q.eq("leadId", lead._id))
|
||||
.order("desc")
|
||||
.take(1);
|
||||
const latestOutreach = outreach[0] ?? null;
|
||||
|
||||
return {
|
||||
id: lead._id,
|
||||
companyName: lead.companyName,
|
||||
niche: lead.niche ?? null,
|
||||
address: lead.address ?? null,
|
||||
city: lead.city ?? null,
|
||||
postalCode: lead.postalCode ?? null,
|
||||
priority: lead.priority,
|
||||
contactStatus: lead.contactStatus,
|
||||
blacklistStatus: lead.blacklistStatus,
|
||||
email: lead.email ?? null,
|
||||
phone: lead.phone ?? null,
|
||||
contactPerson: lead.contactPerson ?? null,
|
||||
websiteDomain: lead.websiteDomain ?? null,
|
||||
outreach: latestOutreach
|
||||
? {
|
||||
approvalStatus: latestOutreach.approvalStatus,
|
||||
sendStatus: latestOutreach.sendStatus,
|
||||
responseStatus: latestOutreach.responseStatus,
|
||||
salesStatus: latestOutreach.salesStatus,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user