Skip to content

Commit 3b4515a

Browse files
committed
Add file for handling GET/POST to /config
1 parent 9a14f53 commit 3b4515a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

global_config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// global_config.js
2+
3+
var Parse = require('parse/node').Parse,
4+
PromiseRouter = require('./PromiseRouter'),
5+
rest = require('./rest');
6+
7+
var router = new PromiseRouter();
8+
9+
// Returns a promise for a {response} object.
10+
function handleUpdateGlobalConfig(req) {
11+
return rest.update(req.config, req.auth,
12+
'_GlobalConfig', 1, req.body)
13+
.then((response) => {
14+
return {response: response};
15+
});
16+
}
17+
18+
// Returns a promise for a {response} object.
19+
function handleGetGlobalConfig(req) {
20+
return rest.find(req.config, req.auth, '_GlobalConfig', 1)
21+
.then((response) => {
22+
if (!response.results || response.results.length == 0) {
23+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
24+
'Object not found.');
25+
} else {
26+
// only return 'params' attribute of response
27+
return {response: { params: response.results[0].params }};
28+
}
29+
});
30+
}
31+
32+
router.route('GET','/config', handleGetGlobalConfig);
33+
router.route('POST','/config', handleUpdateGlobalConfig);
34+
35+
module.exports = router;

0 commit comments

Comments
 (0)