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/customFields.js

38 lines
1.1 KiB

import { escapeRegExp } from '../../../../../lib/escapeRegExp';
import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { LivechatCustomField } from '../../../../models/server/raw';
export async function findLivechatCustomFields({ userId, text, pagination: { offset, count, sort } }) {
if (!await hasPermissionAsync(userId, 'view-l-room')) {
throw new Error('error-not-authorized');
}
const query = { ...text && { $or: [{ label: new RegExp(escapeRegExp(text), 'i') }, { _id: new RegExp(escapeRegExp(text), 'i') }] } };
const cursor = await LivechatCustomField.find(query, {
sort: sort || { label: 1 },
skip: offset,
limit: count,
});
const total = await cursor.count();
const customFields = await cursor.toArray();
return {
customFields,
count: customFields.length,
offset,
total,
};
}
export async function findCustomFieldById({ userId, customFieldId }) {
if (!await hasPermissionAsync(userId, 'view-l-room')) {
throw new Error('error-not-authorized');
}
return {
customField: await LivechatCustomField.findOneById(customFieldId),
};
}