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 pathscans.js
More file actions
41 lines (37 loc) · 1.31 KB
/
Copy pathscans.js
File metadata and controls
41 lines (37 loc) · 1.31 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
var response = require(__dirname + '/../response')
, moment = require('moment')
, Scan = require(__dirname + '/../models/scan')
, Region = require(__dirname + '/../models/region')
, System = require(__dirname + '/../models/system')
exports.show = function(req, res, next) {
var id = req.params.id;
Scan.findOneQ({_id: id})
.then(function(scan) {
if (scan === null) throw 'Invalid Scan ID \'' + id + '\'';
return scan.toObject();
})
.then(function(scan) {
System.findOneQ({id: scan.systemId})
.then(function(system) {
if (!system) throw 'Error looking up system';
return [ scan, system.toObject() ];
})
.spread(function(scan, system) {
Region.findOneQ({id: system.regionID})
.then(function(region) {
if (!region) throw 'Error looking up region';
return res.render('scans', {timestamp: moment.unix(scan.ts).format('lll'), scan: scan, region: region, system: system});
});
})
.catch(function(error) {
console.log(error);
return res.render('scans', {error: 'Invalid Scan ID'});
})
.done();
})
.catch(function(error) {
console.log(error);
return res.render('scans', {error: 'Invalid Scan ID'});
})
.done();
};