@@ -39,6 +39,13 @@ export class UsersController {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Get('public/dashboard/counts')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Get dashboard entity counts for user panel' })
|
||||
getDashboardCounts(@UserId() userId: string) {
|
||||
return this.userService.getDashboardCounts(userId);
|
||||
}
|
||||
|
||||
|
||||
// =================== Admin =====================
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ import { UserRepository } from '../repositories/user.repository';
|
||||
// import { normalizePhone } from '../../util/phone.util';
|
||||
import { UpdateUserDto } from '../dto/update-user.dto';
|
||||
import { CreateUser } from '../interface/user';
|
||||
import { Request } from 'src/modules/request/entities/request.entity';
|
||||
import { Invoice } from 'src/modules/invoice/entities/invoice.entity';
|
||||
import { Order } from 'src/modules/order/entities/order.entity';
|
||||
import { Payment } from 'src/modules/payment/entities/payment.entity';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
@@ -117,4 +121,20 @@ export class UserService {
|
||||
return { message: 'success' }
|
||||
}
|
||||
|
||||
async getDashboardCounts(userId: string) {
|
||||
const [requestsCount, invoicesCount, ordersCount, paymentsCount] = await Promise.all([
|
||||
this.em.count(Request, { user: { id: userId } }),
|
||||
this.em.count(Invoice, { user: { id: userId } }),
|
||||
this.em.count(Order, { user: { id: userId } }),
|
||||
this.em.count(Payment, { invoice: { user: { id: userId } } }),
|
||||
]);
|
||||
|
||||
return {
|
||||
requestsCount,
|
||||
invoicesCount,
|
||||
ordersCount,
|
||||
paymentsCount,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user