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/statistics/server/functions/getStatistics.js

26 lines
640 B

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { Statistics } from '../../../models/server/raw';
export async function getStatistics({ userId, query = {}, pagination: { offset, count, sort, fields } }) {
if (!await hasPermissionAsync(userId, 'view-statistics')) {
throw new Error('error-not-allowed');
}
const cursor = Statistics.find(query, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
fields,
});
const total = await cursor.count();
const statistics = await cursor.toArray();
return {
statistics,
count: statistics.length,
offset,
total,
};
}