update stats

This commit is contained in:
2026-06-18 20:32:46 +03:30
parent 136b067d37
commit 7d4c5f3275
+5 -10
View File
@@ -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(