-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathroute.js
More file actions
42 lines (36 loc) · 1.04 KB
/
route.js
File metadata and controls
42 lines (36 loc) · 1.04 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
const Promise = require('bluebird');
const { getOrganization, getAllOrganizations } = require('./controller');
const { setCache } = require('./cache');
const getOrg = (req, res) => Promise.coroutine(function* () {
const organization = req.params.organization;
const cacheURL = req.originalUrl;
try {
const org = yield getOrganization(organization, cacheURL);
if (org) {
yield setCache(cacheURL, org, 10);
return res.json(org);
}
return res.sendStatus(404);
} catch (e) {
res.status(500);
return res.send(e.message);
}
})();
const getAllOrgs = (req, res) => Promise.coroutine(function* () {
const cacheKey = req.originalUrl;
try {
const allOrganizations = yield getAllOrganizations();
if (allOrganizations && allOrganizations.length > 0) {
yield setCache(cacheKey, allOrganizations, 10);
return res.json(allOrganizations);
}
return res.sendStatus(404);
} catch (e) {
res.status(500);
return res.send(e.message);
}
})();
module.exports = {
getOrg,
getAllOrgs,
};