import { Injectable } from '@nestjs/common'; import { PrismaService } from '../../common/prisma/prisma.module'; @Injectable() export class AdminDashboardService { constructor(private readonly prisma: PrismaService) {} async getStats() { const todayStart = new Date(); todayStart.setHours(0, 0, 0, 0); const [ usersTotal, guestUsers, verifiedUsers, mergedUsers, ordersToday, ordersByStatus, storesTotal, partnersTotal, redeemToday, deliveriesTotal, ] = await Promise.all([ this.prisma.user.count({ where: { status: 1, mergedIntoUserId: null } }), this.prisma.user.count({ where: { status: 1, mergedIntoUserId: null, phoneVerifiedAt: null }, }), this.prisma.user.count({ where: { status: 1, mergedIntoUserId: null, phoneVerifiedAt: { not: null } }, }), this.prisma.user.count({ where: { mergedIntoUserId: { not: null } } }), this.prisma.order.count({ where: { createdAt: { gte: todayStart } } }), this.prisma.order.groupBy({ by: ['status'], _count: { status: true }, }), this.prisma.store.count(), this.prisma.partner.count(), this.prisma.redeemRecord.count({ where: { createdAt: { gte: todayStart } } }), this.prisma.orderDelivery.count(), ]); return { usersTotal, guestUsers, verifiedUsers, mergedUsers, ordersToday, storesTotal, partnersTotal, redeemToday, deliveriesTotal, ordersByStatus: ordersByStatus.map((row) => ({ status: row.status, count: row._count.status, })), }; } }