Recent leads table widget
ui/src/components/adminDashboard/widgets/RecentLeadsTableWidget
Backend
async findFiveRecentLeads(startDate: string, endDate: string, businessesIds: number[], teamId: string) {
const start = dayjs(startDate);
const end = dayjs(endDate);
if (!start.isValid() || !end.isValid()) {
throw new BadRequestException('Invalid date format');
}
const startOfDay = start.startOf('day').toDate();
const endOfDay = end.endOf('day').toDate();
const query = this.leadsRepository
.createQueryBuilder('lead')
.leftJoinAndSelect('lead.business', 'business')
.leftJoinAndSelect('lead.status', 'status');
query.andWhere('lead.teamId = :teamId', { teamId });
query.andWhere('lead.createdAt BETWEEN :startOfDay AND :endOfDay', { startOfDay, endOfDay });
query
.andWhere('business.id IN (:...businessesIds)', { businessesIds })
.orderBy('lead.createdAt', 'DESC')
.take(5);
const recentLeads = await query.getMany();
return recentLeads;
}Last updated