|
|
|
|
@ -5,6 +5,7 @@ import type { PaginatedResult } from '@rocket.chat/rest-typings'; |
|
|
|
|
import { escapeRegExp } from '@rocket.chat/string-helpers'; |
|
|
|
|
import type { FindOptions } from 'mongodb'; |
|
|
|
|
|
|
|
|
|
import { notifyOnLivechatInquiryChangedByRoom, notifyOnRoomChanged } from '../../../../../../app/lib/server/lib/notifyListener'; |
|
|
|
|
import { logger } from '../../lib/logger'; |
|
|
|
|
|
|
|
|
|
type FindPriorityParams = { |
|
|
|
|
@ -24,7 +25,7 @@ export async function findPriority({ |
|
|
|
|
...(text && { $or: [{ name: new RegExp(escapeRegExp(text), 'i') }, { description: new RegExp(escapeRegExp(text), 'i') }] }), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const { cursor, totalCount } = await LivechatPriority.findPaginated(query, { |
|
|
|
|
const { cursor, totalCount } = LivechatPriority.findPaginated(query, { |
|
|
|
|
sort: sort || { name: 1 }, |
|
|
|
|
skip: offset, |
|
|
|
|
limit: count, |
|
|
|
|
@ -64,7 +65,7 @@ export const updateRoomPriority = async ( |
|
|
|
|
user: Required<Pick<IUser, '_id' | 'username' | 'name'>>, |
|
|
|
|
priorityId: string, |
|
|
|
|
): Promise<void> => { |
|
|
|
|
const room = await LivechatRooms.findOneById(rid, { projection: { _id: 1 } }); |
|
|
|
|
const room = await LivechatRooms.findOneById(rid); |
|
|
|
|
if (!room) { |
|
|
|
|
throw new Error('error-room-does-not-exist'); |
|
|
|
|
} |
|
|
|
|
@ -79,10 +80,15 @@ export const updateRoomPriority = async ( |
|
|
|
|
LivechatInquiry.setPriorityForRoom(rid, priority), |
|
|
|
|
addPriorityChangeHistoryToRoom(room._id, user, priority), |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
void notifyOnRoomChanged({ ...room, priorityId: priority._id, priorityWeight: priority.sortItem }, 'updated'); |
|
|
|
|
void notifyOnLivechatInquiryChangedByRoom(rid, 'updated'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const removePriorityFromRoom = async (rid: string, user: Required<Pick<IUser, '_id' | 'username' | 'name'>>): Promise<void> => { |
|
|
|
|
const room = await LivechatRooms.findOneById<Pick<IOmnichannelRoom, '_id'>>(rid, { projection: { _id: 1 } }); |
|
|
|
|
const room = await LivechatRooms.findOneById<Omit<IOmnichannelRoom, 'priorityId' | 'priorityWeight'>>(rid, { |
|
|
|
|
projection: { priorityId: 0, priorityWeight: 0 }, |
|
|
|
|
}); |
|
|
|
|
if (!room) { |
|
|
|
|
throw new Error('error-room-does-not-exist'); |
|
|
|
|
} |
|
|
|
|
@ -92,6 +98,9 @@ export const removePriorityFromRoom = async (rid: string, user: Required<Pick<IU |
|
|
|
|
LivechatInquiry.unsetPriorityForRoom(rid), |
|
|
|
|
addPriorityChangeHistoryToRoom(rid, user), |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
void notifyOnRoomChanged(room, 'updated'); |
|
|
|
|
void notifyOnLivechatInquiryChangedByRoom(rid, 'updated'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const addPriorityChangeHistoryToRoom = async ( |
|
|
|
|
|