-
Notifications
You must be signed in to change notification settings - Fork 10k
/
afterRemoveDepartment.ts
30 lines (23 loc) · 1.17 KB
/
afterRemoveDepartment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { ILivechatAgent, ILivechatDepartmentRecord } from '@rocket.chat/core-typings';
import { LivechatDepartment } from '@rocket.chat/models';
import { callbacks } from '../../../../../lib/callbacks';
import { cbLogger } from '../lib/logger';
const afterRemoveDepartment = async (options: { department: ILivechatDepartmentRecord; agentsId: ILivechatAgent['_id'][] }) => {
cbLogger.debug(`Performing post-department-removal actions in EE: ${options?.department?._id}. Removing department from forward list`);
if (!options || !options.department) {
cbLogger.warn('No department found in options', options);
return options;
}
const { department } = options;
cbLogger.debug(`Removing department from forward list: ${department._id}`);
await LivechatDepartment.removeDepartmentFromForwardListById(department._id);
cbLogger.debug(`Removed department from forward list: ${department._id}`);
cbLogger.debug(`Post-department-removal actions completed in EE: ${department._id}`);
return options;
};
callbacks.add(
'livechat.afterRemoveDepartment',
(options) => Promise.await(afterRemoveDepartment(options)),
callbacks.priority.HIGH,
'livechat-after-remove-department',
);