Add file for handling GET/POST to /config

This commit is contained in:
Peter Theill
2016-02-07 00:13:42 +01:00
parent 9a14f53e45
commit 3b4515ac43

35
global_config.js Normal file
View File

@@ -0,0 +1,35 @@
// global_config.js
var Parse = require('parse/node').Parse,
PromiseRouter = require('./PromiseRouter'),
rest = require('./rest');
var router = new PromiseRouter();
// Returns a promise for a {response} object.
function handleUpdateGlobalConfig(req) {
return rest.update(req.config, req.auth,
'_GlobalConfig', 1, req.body)
.then((response) => {
return {response: response};
});
}
// Returns a promise for a {response} object.
function handleGetGlobalConfig(req) {
return rest.find(req.config, req.auth, '_GlobalConfig', 1)
.then((response) => {
if (!response.results || response.results.length == 0) {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
'Object not found.');
} else {
// only return 'params' attribute of response
return {response: { params: response.results[0].params }};
}
});
}
router.route('GET','/config', handleGetGlobalConfig);
router.route('POST','/config', handleUpdateGlobalConfig);
module.exports = router;