Rearrange methods to follow route setup
This commit is contained in:
@@ -5,6 +5,19 @@ var Parse = require('parse/node').Parse,
|
|||||||
|
|
||||||
var router = new PromiseRouter();
|
var router = new PromiseRouter();
|
||||||
|
|
||||||
|
function getGlobalConfig(req) {
|
||||||
|
return req.config.database.rawCollection('_GlobalConfig')
|
||||||
|
.then(coll => coll.findOne({'_id': 1}))
|
||||||
|
.then(globalConfig => ({response: { params: globalConfig.params }}))
|
||||||
|
.catch(() => ({
|
||||||
|
status: 404,
|
||||||
|
response: {
|
||||||
|
code: Parse.Error.INVALID_KEY_NAME,
|
||||||
|
error: 'config does not exist',
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function updateGlobalConfig(req) {
|
function updateGlobalConfig(req) {
|
||||||
if (!req.auth.isMaster) {
|
if (!req.auth.isMaster) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
@@ -27,19 +40,6 @@ function updateGlobalConfig(req) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGlobalConfig(req) {
|
|
||||||
return req.config.database.rawCollection('_GlobalConfig')
|
|
||||||
.then(coll => coll.findOne({'_id': 1}))
|
|
||||||
.then(globalConfig => ({response: { params: globalConfig.params }}))
|
|
||||||
.catch(() => ({
|
|
||||||
status: 404,
|
|
||||||
response: {
|
|
||||||
code: Parse.Error.INVALID_KEY_NAME,
|
|
||||||
error: 'config does not exist',
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
router.route('GET', '/config', getGlobalConfig);
|
router.route('GET', '/config', getGlobalConfig);
|
||||||
router.route('PUT', '/config', updateGlobalConfig);
|
router.route('PUT', '/config', updateGlobalConfig);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user