3 var policyFactory = require('gitter-web-permissions/lib/policy-factory');
4 var chatHeapmapAggregator = require('gitter-web-elasticsearch/lib/chat-heatmap-aggregator');
5 var moment = require('moment');
6 var StatusError = require('statuserror');
7 var debug = require('debug')('gitter:app:chat-heapmap-route');
9 module.exports = function(req, res, next) {
10 var roomId = req.params.roomId;
12 // Expand the date range to sort out timezone issues
13 var start = req.query.start
14 ? moment(req.query.start)
18 var end = req.query.end
19 ? moment(req.query.end)
23 var tz = req.query.tz ? req.query.tz : 0;
26 .createPolicyForRoomId(req.user, roomId)
27 .then(function(policy) {
28 return policy.canRead();
30 .then(function(hasReadAccess) {
31 if (!hasReadAccess) throw new StatusError(404);
33 debug('Searching troupeId=%s start=%s end=%s tz=%s', roomId, start, end, tz);
35 return chatHeapmapAggregator.getHeatmapForRoom(roomId, start, end, tz);
37 .then(function(chatActivity) {
38 res.send(chatActivity);