The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/models/server/raw/LivechatDepartment.js

81 lines
1.7 KiB

import { escapeRegExp } from '@rocket.chat/string-helpers';
import { BaseRaw } from './BaseRaw';
export class LivechatDepartmentRaw extends BaseRaw {
findInIds(departmentsIds, options) {
const query = { _id: { $in: departmentsIds } };
return this.find(query, options);
}
findByNameRegexWithExceptionsAndConditions(searchTerm, exceptions = [], conditions = {}, options = {}) {
if (!Array.isArray(exceptions)) {
exceptions = [exceptions];
}
const nameRegex = new RegExp(`^${ escapeRegExp(searchTerm).trim() }`, 'i');
const query = {
name: nameRegex,
_id: {
$nin: exceptions,
},
...conditions,
};
return this.find(query, options);
}
findByBusinessHourId(businessHourId, options) {
const query = { businessHourId };
return this.find(query, options);
}
findEnabledByBusinessHourId(businessHourId, options) {
const query = { businessHourId, enabled: true };
return this.find(query, options);
}
addBusinessHourToDepartmentsByIds(ids = [], businessHourId) {
const query = {
_id: { $in: ids },
};
const update = {
$set: {
businessHourId,
},
};
return this.col.update(query, update, { multi: true });
}
removeBusinessHourFromDepartmentsByIdsAndBusinessHourId(ids = [], businessHourId) {
const query = {
_id: { $in: ids },
businessHourId,
};
const update = {
$unset: {
businessHourId: 1,
},
};
return this.col.update(query, update, { multi: true });
}
removeBusinessHourFromDepartmentsByBusinessHourId(businessHourId) {
const query = {
businessHourId,
};
const update = {
$unset: {
businessHourId: 1,
},
};
return this.col.update(query, update, { multi: true });
}
}