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/livechat/server/api/lib/triggers.js

33 lines
859 B

import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { LivechatTrigger } from '../../../../models/server/raw';
export async function findTriggers({ userId, pagination: { offset, count, sort } }) {
if (!await hasPermissionAsync(userId, 'view-livechat-manager')) {
throw new Error('error-not-authorized');
}
const cursor = await LivechatTrigger.find({}, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
});
const total = await cursor.count();
const triggers = await cursor.toArray();
return {
triggers,
count: triggers.length,
offset,
total,
};
}
export async function findTriggerById({ userId, triggerId }) {
if (!await hasPermissionAsync(userId, 'view-livechat-manager')) {
throw new Error('error-not-authorized');
}
return LivechatTrigger.findOneById(triggerId);
}