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/packages/rocketchat-api/server/v1/stats.js

44 lines
1.1 KiB

RocketChat.API.v1.addRoute('statistics', { authRequired: true }, {
get() {
let refresh = false;
if (typeof this.queryParams.refresh !== 'undefined' && this.queryParams.refresh === 'true') {
refresh = true;
}
let stats;
Meteor.runAsUser(this.userId, () => {
stats = Meteor.call('getStatistics', refresh);
});
return RocketChat.API.v1.success({
statistics: stats
});
}
});
RocketChat.API.v1.addRoute('statistics.list', { authRequired: true }, {
get() {
if (!RocketChat.authz.hasPermission(this.userId, 'view-statistics')) {
return RocketChat.API.v1.unauthorized();
}
const { offset, count } = this.getPaginationItems();
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query);
const statistics = RocketChat.models.Statistics.find(ourQuery, {
sort: sort ? sort : { name: 1 },
skip: offset,
limit: count,
fields: Object.assign({}, fields, RocketChat.API.v1.defaultFieldsToExclude)
}).fetch();
return RocketChat.API.v1.success({
statistics,
count: statistics.length,
offset,
total: RocketChat.models.Statistics.find(ourQuery).count()
});
}
});