-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdashboard.js
executable file
·56 lines (47 loc) · 1.9 KB
/
dashboard.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require('express');
const router = express.Router({ mergeParams: true });
const db = require('../db');
const { requireUser } = require('../lib/access-helpers');
router.get('/', requireUser, async (req, res) => {
const result = {};
let agencyCriteria;
const { selectedAgency } = req.session;
if (req.query.totalGrants || req.query.grantsCreatedFromTs || req.query.grantsUpdatedFromTs) {
agencyCriteria = await db.getAgencyCriteriaForAgency(selectedAgency);
}
if (req.query.totalGrants) {
result.totalGrants = await db.getTotalGrants();
result.totalGrantsMatchingAgencyCriteria = await db.getTotalGrants({ agencyCriteria });
}
if (req.query.totalViewedGrants) {
result.totalViewedGrants = await db.getTotalViewedGrants();
}
if (req.query.totalInterestedGrants) {
result.totalInterestedGrants = await db.getTotalInterestedGrants(selectedAgency);
}
if (req.query.totalInterestedGrantsByAgencies) {
result.totalInterestedGrantsByAgencies = await db.getTotalInterestedGrantsByAgencies(selectedAgency);
}
if (req.query.grantsCreatedFromTs) {
const fromTs = req.query.grantsCreatedFromTs;
result.grantsCreatedInTimeframe = await db.getTotalGrants({
createdTsBounds: { fromTs },
});
result.grantsCreatedInTimeframeMatchingCriteria = await db.getTotalGrants({
createdTsBounds: { fromTs },
agencyCriteria,
});
}
if (req.query.grantsUpdatedFromTs) {
const fromTs = req.query.grantsUpdatedFromTs;
result.grantsUpdatedInTimeframe = await db.getTotalGrants({
updatedTsBounds: { fromTs },
});
result.grantsUpdatedInTimeframeMatchingCriteria = await db.getTotalGrants({
updatedTsBounds: { fromTs },
agencyCriteria,
});
}
res.json(result);
});
module.exports = router;