This commit is contained in:
@@ -51,10 +51,10 @@ export class AdminController {
|
|||||||
return this.adminService.updateMe(adminId, dto);
|
return this.adminService.updateMe(adminId, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('admin/dashboard/counts')
|
@Get('admin/menu/counts')
|
||||||
@ApiOperation({ summary: 'Get dashboard entity counts for admin panel' })
|
@ApiOperation({ summary: 'Get metrics for admin panel' })
|
||||||
getDashboardCounts() {
|
getDashboardCounts(@AdminId() adminId: string) {
|
||||||
return this.adminService.getDashboardCounts();
|
return this.adminService.getDashboardCounts(adminId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('admin/home/stats')
|
@Get('admin/home/stats')
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export class AdminService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rest.phone !== undefined && rest.phone !== admin.phone) {
|
if (rest.phone !== undefined && rest.phone !== admin.phone) {
|
||||||
const exists = await this.adminRepository.findOne({ phone: rest.phone,id: { $ne: adminId } });
|
const exists = await this.adminRepository.findOne({ phone: rest.phone, id: { $ne: adminId } });
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw new ConflictException('This Phone Number is already taken');
|
throw new ConflictException('This Phone Number is already taken');
|
||||||
}
|
}
|
||||||
@@ -165,11 +165,25 @@ export class AdminService {
|
|||||||
return permissionNames.filter((name) => adminPermissionNames.has(name))
|
return permissionNames.filter((name) => adminPermissionNames.has(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDashboardCounts() {
|
async getDashboardCounts(adminId: string) {
|
||||||
|
const permissions = await this.ownedPermissions(adminId, [
|
||||||
|
PermissionEnum.VIEW_ORDERS,
|
||||||
|
PermissionEnum.VIEW_ASSIGNED_ORDERS,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const canViewAnyOrder = permissions.includes(PermissionEnum.VIEW_ORDERS);
|
||||||
|
const canViewAssignedOrder = permissions.includes(PermissionEnum.VIEW_ASSIGNED_ORDERS);
|
||||||
|
|
||||||
|
const ordersCountPromise = canViewAnyOrder
|
||||||
|
? this.em.count(Order)
|
||||||
|
: canViewAssignedOrder
|
||||||
|
? this.em.count(Order, { designers: { designer: { id: adminId } } })
|
||||||
|
: Promise.resolve(0);
|
||||||
|
|
||||||
const [requestsCount, invoicesCount, ordersCount, paymentsCount] = await Promise.all([
|
const [requestsCount, invoicesCount, ordersCount, paymentsCount] = await Promise.all([
|
||||||
this.em.count(Request),
|
this.em.count(Request),
|
||||||
this.em.count(Invoice),
|
this.em.count(Invoice, { status: { $nin: [InvoiceConfirmStatusEnum.ARCHIVED] } }),
|
||||||
this.em.count(Order),
|
ordersCountPromise,
|
||||||
this.em.count(Payment),
|
this.em.count(Payment),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ export class UsersController {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('public/dashboard/counts')
|
@Get('public/menu/counts')
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiOperation({ summary: 'Get dashboard entity counts for user panel' })
|
@ApiOperation({ summary: 'Get metrics for user panel' })
|
||||||
getDashboardCounts(@UserId() userId: string) {
|
getDashboardCounts(@UserId() userId: string) {
|
||||||
return this.userService.getDashboardCounts(userId);
|
return this.userService.getDashboardCounts(userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { Request } from 'src/modules/request/entities/request.entity';
|
|||||||
import { Invoice } from 'src/modules/invoice/entities/invoice.entity';
|
import { Invoice } from 'src/modules/invoice/entities/invoice.entity';
|
||||||
import { Order } from 'src/modules/order/entities/order.entity';
|
import { Order } from 'src/modules/order/entities/order.entity';
|
||||||
import { Payment } from 'src/modules/payment/entities/payment.entity';
|
import { Payment } from 'src/modules/payment/entities/payment.entity';
|
||||||
|
import { InvoiceConfirmStatusEnum } from 'src/modules/invoice/enum/invoice-confirm-status.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@@ -125,7 +126,7 @@ export class UserService {
|
|||||||
async getDashboardCounts(userId: string) {
|
async getDashboardCounts(userId: string) {
|
||||||
const [requestsCount, invoicesCount, ordersCount, paymentsCount] = await Promise.all([
|
const [requestsCount, invoicesCount, ordersCount, paymentsCount] = await Promise.all([
|
||||||
this.em.count(Request, { user: { id: userId } }),
|
this.em.count(Request, { user: { id: userId } }),
|
||||||
this.em.count(Invoice, { user: { id: userId } }),
|
this.em.count(Invoice, { user: { id: userId }, status: { $nin: [InvoiceConfirmStatusEnum.ARCHIVED] } }),
|
||||||
this.em.count(Order, { user: { id: userId } }),
|
this.em.count(Order, { user: { id: userId } }),
|
||||||
this.em.count(Payment, { invoice: { user: { id: userId } } }),
|
this.em.count(Payment, { invoice: { user: { id: userId } } }),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user