This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreports.js
More file actions
43 lines (35 loc) · 1.37 KB
/
Copy pathreports.js
File metadata and controls
43 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var response = require(__dirname + '/../response')
, _ = require('lodash')
, Q = require('q')
, Report = require(__dirname + '/../models/report')
, System = require(__dirname + '/../models/system')
exports.list = function(req, res, next) {
var tasks = [
System.find({}, '-_id').lean().execQ(),
Report.findQ({$or: [{type: 'wormhole'}, {type: 'wormhole_update'}]}, '-_id -__v')
];
Q.all(tasks)
.then(function(results) {
var reports = [];
var systems = results[0];
_.each(results[1], function(result) {
var report = {
type: result.type,
toSystemId: result.data[0].toSystem,
toSystemName: _.find(systems, function(system) { return system.id == result.data[0].toSystem }).name,
fromSystemId: result.data[0].fromSystem,
fromSystemName: _.find(systems, function(system) { return system.id == result.data[0].fromSystem }).name,
reporterId: result.reporterId || '0',
reporterName: result.reporterName || 'Admin',
ts: result.ts
};
if (report.type == 'wormhole_update' && result.data[0].info.match(/Wormhole collapsed/)) report.cleared = true;
reports.push(report);
});
return res.jsonp({reports: reports});
})
.catch(function(error) {
return res.render('reports', {error: error});
})
.done();
};