fix: add notiftype
This commit is contained in:
@@ -101,8 +101,10 @@ export class TicketsService {
|
||||
async toggleCategoryStatus(paramDto: ParamDto) {
|
||||
const category = await this.ticketsCategoryRepository.findCategoryById(paramDto.id);
|
||||
if (!category) throw new BadRequestException(TicketMessageEnum.CATEGORY_NOT_FOUND);
|
||||
//
|
||||
category.isActive = !category.isActive;
|
||||
await this.ticketsCategoryRepository.save(category);
|
||||
//
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
isActive: category.isActive,
|
||||
@@ -119,7 +121,10 @@ export class TicketsService {
|
||||
let service;
|
||||
const user = await this.usersService.findOneByIdWithQueryRunner(userId, queryRunner);
|
||||
|
||||
const ticketCategory = await queryRunner.manager.findOneBy(TicketCategory, { id: createDto.categoryId });
|
||||
const ticketCategory = await queryRunner.manager.findOne(TicketCategory, {
|
||||
where: { id: createDto.categoryId },
|
||||
relations: { group: { users: true } },
|
||||
});
|
||||
if (!ticketCategory) throw new BadRequestException(TicketMessageEnum.CATEGORY_NOT_FOUND);
|
||||
|
||||
const { attachmentUrls } = createDto;
|
||||
@@ -149,6 +154,25 @@ export class TicketsService {
|
||||
|
||||
await queryRunner.manager.save(Ticket, ticket);
|
||||
|
||||
const assignedUser = await this.autoAssignUser(ticketCategory);
|
||||
//send notification to assignedUser
|
||||
if (assignedUser) {
|
||||
ticket.assignedTo = assignedUser;
|
||||
await queryRunner.manager.save(Ticket, ticket);
|
||||
await this.notificationsService.createAssignTicketNotificationForAdmin(
|
||||
assignedUser.id,
|
||||
{
|
||||
ticketId: ticket.numericId.toString(),
|
||||
subject: ticket.subject,
|
||||
date: ticket.createdAt,
|
||||
userPhone: user.phone,
|
||||
userEmail: user.email,
|
||||
user: `${user.firstName} ${user.lastName}`,
|
||||
},
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
|
||||
await this.notificationsService.createTicketNotification(
|
||||
userId,
|
||||
{
|
||||
@@ -374,4 +398,17 @@ export class TicketsService {
|
||||
});
|
||||
return ticketCount;
|
||||
}
|
||||
|
||||
//******************************** */
|
||||
async autoAssignUser(category: TicketCategory): Promise<User | null> {
|
||||
if (!category.group) return null;
|
||||
|
||||
const { users } = await this.usersService.getUsersByGroup(category.group.id);
|
||||
|
||||
if (users.length === 0) return null;
|
||||
|
||||
users.sort((a, b) => (a.tickets.length || 0) - (b.tickets.length || 0));
|
||||
|
||||
return users[0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user