-
Notifications
You must be signed in to change notification settings - Fork 10k
/
LivechatDepartment.js
58 lines (50 loc) · 1.83 KB
/
LivechatDepartment.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Meteor } from 'meteor/meteor';
import { LivechatDepartment } from '../../../../../app/models/server/models/LivechatDepartment';
import { LivechatDepartment as LivechatDepartmentModel } from '../../../../../app/models/server';
import { LivechatUnit } from '../index';
import { overwriteClassOnLicense } from '../../../license/server';
const { find, findOne, update, remove } = LivechatDepartment.prototype;
overwriteClassOnLicense('livechat-enterprise', LivechatDepartment, {
unfilteredFind(originalFn, ...args) {
return find.apply(this, args);
},
unfilteredFindOne(originalFn, ...args) {
return findOne.apply(this, args);
},
unfilteredUpdate(originalFn, ...args) {
return update.apply(this, args);
},
unfilteredRemove(originalFn, ...args) {
return remove.apply(this, args);
},
createOrUpdateDepartment(originalFn, ...args) {
if (args.length > 2 && !args[1].type) {
args[1].type = 'd';
}
if (args[1] && args[1].departmentsAllowedToForward) {
args[1].departmentsAllowedToForward = args[1].departmentsAllowedToForward.split(',');
}
return originalFn.apply(this, args);
},
removeParentAndAncestorById(originalFn, parentId) {
const query = {
parentId,
};
const update = {
$unset: { parentId: 1 },
$pull: { ancestors: parentId },
};
return this.update(query, update, { multi: true });
},
findEnabledWithAgentsAndBusinessUnit(originalFn, businessUnit, fields = undefined) {
if (!businessUnit) {
return LivechatDepartmentModel.findEnabledWithAgents(fields);
}
const unit = LivechatUnit.findOneById(businessUnit, { fields: { _id: 1 } });
if (!unit) {
throw new Meteor.Error('error-unit-not-found', `Error! No Active Business Unit found with id: ${businessUnit}`);
}
return LivechatDepartmentModel.findActiveByUnitIds([businessUnit], { fields });
},
});
export default LivechatDepartment;