Merge pull request #1210 from framp/master
Make GlobalConfig work like parse.com
This commit is contained in:
@@ -2,15 +2,17 @@ import { version } from '../../package.json';
|
||||
import PromiseRouter from '../PromiseRouter';
|
||||
import * as middleware from "../middlewares";
|
||||
|
||||
const isGlobalConfigEnabled = !!(process.env.PARSE_EXPERIMENTAL_CONFIG_ENABLED || process.env.TESTING)
|
||||
|
||||
export class FeaturesRouter extends PromiseRouter {
|
||||
mountRoutes() {
|
||||
this.route('GET','/serverInfo', middleware.promiseEnforceMasterKeyAccess, req => {
|
||||
const features = {
|
||||
globalConfig: {
|
||||
create: false,
|
||||
read: false,
|
||||
update: false,
|
||||
delete: false,
|
||||
create: isGlobalConfigEnabled,
|
||||
read: isGlobalConfigEnabled,
|
||||
update: isGlobalConfigEnabled,
|
||||
delete: isGlobalConfigEnabled,
|
||||
},
|
||||
hooks: {
|
||||
create: false,
|
||||
|
||||
@@ -18,8 +18,19 @@ export class GlobalConfigRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
updateGlobalConfig(req) {
|
||||
const params = req.body.params;
|
||||
const update = Object.keys(params).reduce((acc, key) => {
|
||||
if(params[key] && params[key].__op && params[key].__op === "Delete") {
|
||||
if (!acc.$unset) acc.$unset = {};
|
||||
acc.$unset[`params.${key}`] = "";
|
||||
} else {
|
||||
if (!acc.$set) acc.$set = {};
|
||||
acc.$set[`params.${key}`] = params[key];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
return req.config.database.adaptiveCollection('_GlobalConfig')
|
||||
.then(coll => coll.upsertOne({ _id: 1 }, { $set: req.body }))
|
||||
.then(coll => coll.upsertOne({ _id: 1 }, update))
|
||||
.then(() => ({ response: { result: true } }));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user