chore: fetch ticket that only assing to a admin and only super admin can see all ticket
This commit is contained in:
@@ -243,10 +243,11 @@ export class TicketsService {
|
||||
return { tickets, count, paginate: true };
|
||||
}
|
||||
//******************************** */
|
||||
//TODO: get for admin with group of category
|
||||
async getTicketForAdmin(queryDto: SearchTicketQueryDto) {
|
||||
async getTicketForAdmin(queryDto: SearchTicketQueryDto, adminId: string) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const isSuperAdmin = await this.usersService.isSuperAdmin(adminId);
|
||||
|
||||
const queryBuilder = this.ticketsRepository
|
||||
.createQueryBuilder("ticket")
|
||||
.leftJoinAndSelect("ticket.category", "category")
|
||||
@@ -255,6 +256,10 @@ export class TicketsService {
|
||||
.leftJoinAndSelect("ticket.danakService", "danakService")
|
||||
.orderBy("ticket.createdAt", "DESC");
|
||||
|
||||
if (!isSuperAdmin) {
|
||||
queryBuilder.andWhere("ticket.assignedToId = :adminId", { adminId });
|
||||
}
|
||||
|
||||
if (queryDto.status) {
|
||||
queryBuilder.andWhere("ticket.status = :status", { status: queryDto.status });
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ export class TicketsController {
|
||||
@PermissionsDec(PermissionEnum.TICKETS)
|
||||
@Pagination()
|
||||
@Get("admin")
|
||||
getAllTickets(@Query() queryDto: SearchTicketQueryDto) {
|
||||
return this.ticketsService.getTicketForAdmin(queryDto);
|
||||
getAllTickets(@Query() queryDto: SearchTicketQueryDto, @UserDec("id") adminId: string) {
|
||||
return this.ticketsService.getTicketForAdmin(queryDto, adminId);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "create ticket messages" })
|
||||
|
||||
Reference in New Issue
Block a user