fix: bug in the customer and tikcet for admin panel
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsEnum, IsOptional } from "class-validator";
|
||||
import { IsEnum, IsOptional, IsUUID } from "class-validator";
|
||||
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { UserMessage } from "../../../common/enums/message.enum";
|
||||
import { TicketStatus } from "../enums/ticket-status.enum";
|
||||
|
||||
export class SearchTicketQueryDto extends PaginationDto {
|
||||
@IsOptional()
|
||||
@IsEnum(TicketStatus)
|
||||
@ApiPropertyOptional({ enum: TicketStatus, description: "ticket status", example: TicketStatus.PENDING })
|
||||
status: TicketStatus;
|
||||
status?: TicketStatus;
|
||||
|
||||
@IsOptional()
|
||||
@IsUUID("4", { message: UserMessage.USER_ID_SHOULD_BE_A_UUID })
|
||||
@ApiPropertyOptional({ description: "user id", example: "123e4567-e89b-12d3-a456-426614174000" })
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, HttpException, Injectable, InternalServerErrorException, Logger } from "@nestjs/common";
|
||||
import { DataSource, FindManyOptions, Not } from "typeorm";
|
||||
import { DataSource, Not } from "typeorm";
|
||||
|
||||
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||
import { CommonMessage, TicketMessageEnum, UserMessage } from "../../../common/enums/message.enum";
|
||||
@@ -220,25 +220,26 @@ export class TicketsService {
|
||||
}
|
||||
//******************************** */
|
||||
//TODO: get for admin with group of category
|
||||
async getAllTickets(queryDto: SearchTicketQueryDto) {
|
||||
async getTicketForAdmin(queryDto: SearchTicketQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const findOptions: FindManyOptions<Ticket> = {
|
||||
where: {
|
||||
...(queryDto.status && { status: queryDto.status }),
|
||||
},
|
||||
relations: {
|
||||
category: true,
|
||||
user: true,
|
||||
assignedTo: true,
|
||||
danakService: true,
|
||||
},
|
||||
order: { createdAt: "DESC" as const },
|
||||
skip,
|
||||
take: limit,
|
||||
};
|
||||
const queryBuilder = this.ticketsRepository
|
||||
.createQueryBuilder("ticket")
|
||||
.leftJoinAndSelect("ticket.category", "category")
|
||||
.leftJoinAndSelect("ticket.user", "user")
|
||||
.leftJoinAndSelect("ticket.assignedTo", "assignedTo")
|
||||
.leftJoinAndSelect("ticket.danakService", "danakService")
|
||||
.orderBy("ticket.createdAt", "DESC");
|
||||
|
||||
const [tickets, count] = await this.ticketsRepository.findAndCount(findOptions);
|
||||
if (queryDto.status) {
|
||||
queryBuilder.andWhere("ticket.status = :status", { status: queryDto.status });
|
||||
}
|
||||
|
||||
if (queryDto.userId) {
|
||||
queryBuilder.andWhere("user.id = :userId", { userId: queryDto.userId });
|
||||
}
|
||||
|
||||
const [tickets, count] = await queryBuilder.skip(skip).take(limit).getManyAndCount();
|
||||
|
||||
return { tickets, count, paginate: true };
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export class TicketsController {
|
||||
@Pagination()
|
||||
@Get("admin")
|
||||
getAllTickets(@Query() queryDto: SearchTicketQueryDto) {
|
||||
return this.ticketsService.getAllTickets(queryDto);
|
||||
return this.ticketsService.getTicketForAdmin(queryDto);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "create ticket messages" })
|
||||
|
||||
Reference in New Issue
Block a user