Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / handlers / snapshots / admin-chat-message-report-snapshot.js
blob41589627f11382c7ca15ea2b27aa03a2552c149e
1 'use strict';
3 const mongoUtils = require('gitter-web-persistence-utils/lib/mongo-utils');
4 const restSerializer = require('../../serializers/rest-serializer');
5 const chatReportService = require('gitter-web-chat-reports');
7 function postprocessUser(user) {
8   if (user) {
9     return Object.assign({}, user, {
10       accountCreatedDate: mongoUtils.getTimestampFromObjectId(user.id)
11     });
12   }
15 function getSnapshotsForPageContext(req) {
16   return chatReportService
17     .findChatMessageReports({
18       beforeId: req.query.beforeId,
19       afterId: req.query.afterId,
20       limit: req.query.limit
21     })
22     .then(function(reports) {
23       const strategy = new restSerializer.ChatMessageReportStrategy();
24       return restSerializer.serialize(reports, strategy);
25     })
26     .then(serializedReports => {
27       return {
28         adminChatMessageReportDashboard: {
29           reports: serializedReports.map(report => {
30             return Object.assign({}, report, {
31               reporterUser: postprocessUser(report.reporterUser),
32               messageUser: postprocessUser(report.messageUser)
33             });
34           })
35         }
36       };
37     });
40 module.exports = getSnapshotsForPageContext;