From 7d4c5f32756f5a09f098c72b66a6d3242dc10e9c Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 18 Jun 2026 20:32:46 +0330 Subject: [PATCH] update stats --- src/modules/orders/providers/orders.service.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/modules/orders/providers/orders.service.ts b/src/modules/orders/providers/orders.service.ts index 6c63ba3..c400cbf 100644 --- a/src/modules/orders/providers/orders.service.ts +++ b/src/modules/orders/providers/orders.service.ts @@ -3,6 +3,7 @@ import { EntityManager } from '@mikro-orm/postgresql'; import { Order } from '../entities/order.entity'; import { OrderItem } from '../entities/order-item.entity'; import { User } from '../../users/entities/user.entity'; +import { UserRestaurant } from '../../users/entities/user-restuarant.entity'; import { Restaurant } from '../../restaurants/entities/restaurant.entity'; import { Food } from '../../foods/entities/food.entity'; import { CartService } from '../../cart/providers/cart.service'; @@ -649,16 +650,10 @@ console.log(cart); isActive: true, }); - // 3. Total clients count (distinct users with orders for this restaurant) - const clientsResult = await em.execute( - ` - SELECT COUNT(DISTINCT o.user_id) as count - FROM orders o - WHERE o.restaurant_id = ? - `, - [restId], - ); - const totalClients = Number(clientsResult[0]?.count || 0); + // 3. Total clients count (users linked to this restaurant) + const totalClients = await em.count(UserRestaurant, { + restaurant: { id: restId }, + }); // 4. Total revenue (sum of paid payments for orders of this restaurant) const revenueResult = await em.execute(