From 3b4515ac439cde1a552d33a664e7e08eb9112e77 Mon Sep 17 00:00:00 2001 From: Peter Theill Date: Sun, 7 Feb 2016 00:13:42 +0100 Subject: [PATCH] Add file for handling GET/POST to /config --- global_config.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 global_config.js diff --git a/global_config.js b/global_config.js new file mode 100644 index 00000000..56eafc3c --- /dev/null +++ b/global_config.js @@ -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; \ No newline at end of file