update stats
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user