fix: bug in the assign to user check
This commit is contained in:
@@ -252,6 +252,8 @@ export class TicketsService {
|
||||
if (ticket.status === TicketStatus.CLOSED) throw new BadRequestException(TicketMessageEnum.TICKET_CLOSED);
|
||||
|
||||
const isSuperAdmin = await this.usersService.isSuperAdmin(userId);
|
||||
console.log(isSuperAdmin);
|
||||
console.log(ticket.assignedTo);
|
||||
if (!isSuperAdmin && ticket.assignedTo?.id !== userId) throw new BadRequestException(TicketMessageEnum.TICKET_NOT_ASSIGNED_TO_USER);
|
||||
|
||||
const user = await queryRunner.manager.findOneBy(User, { id: userId });
|
||||
@@ -351,6 +353,7 @@ export class TicketsService {
|
||||
if (users.length === 0) return null;
|
||||
|
||||
users.sort((a, b) => (a.tickets.length || 0) - (b.tickets.length || 0));
|
||||
console.log(users);
|
||||
|
||||
return users[0];
|
||||
}
|
||||
@@ -393,8 +396,11 @@ export class TicketsService {
|
||||
|
||||
private async findTicket(queryRunner: QueryRunner, ticketId: string, userId: string, isAdmin: boolean): Promise<Ticket> {
|
||||
const ticket = isAdmin
|
||||
? await queryRunner.manager.findOne(Ticket, { where: { id: ticketId }, relations: { user: true } })
|
||||
: await queryRunner.manager.findOne(Ticket, { where: { id: ticketId, user: { id: userId } }, relations: { user: true } });
|
||||
? await queryRunner.manager.findOne(Ticket, { where: { id: ticketId }, relations: { user: true, assignedTo: true } })
|
||||
: await queryRunner.manager.findOne(Ticket, {
|
||||
where: { id: ticketId, user: { id: userId } },
|
||||
relations: { user: true, assignedTo: true },
|
||||
});
|
||||
|
||||
if (!ticket) throw new BadRequestException(TicketMessageEnum.TICKET_NOT_FOUND);
|
||||
return ticket;
|
||||
|
||||
Reference in New Issue
Block a user