Added defaultConfig parameter to the options

This commit is contained in:
Ruben Paz 2016-06-05 14:44:24 +01:00
parent f8e1a27572
commit 9a28dbcc02
4 changed files with 59 additions and 25 deletions

View File

@ -4,9 +4,11 @@ import { capitalize } from 'lodash/string';
import { getMethod } from '../utils'; import { getMethod } from '../utils';
let prefix; let prefix;
let defaultConfig;
export default (server, a, b, names, options) => { export default (server, a, b, names, options) => {
prefix = options.prefix; prefix = options.prefix;
defaultConfig = options.defaultConfig;
server.route({ server.route({
method: 'GET', method: 'GET',
@ -31,6 +33,8 @@ export default (server, a, b, names, options) => {
await fn(instanceb); await fn(instanceb);
reply([instancea, instanceb]); reply([instancea, instanceb]);
} },
config: defaultConfig
}) })
} }

View File

@ -4,9 +4,11 @@ import _ from 'lodash';
import { parseInclude, parseWhere, getMethod } from '../utils'; import { parseInclude, parseWhere, getMethod } from '../utils';
let prefix; let prefix;
let defaultConfig;
export default (server, a, b, names, options) => { export default (server, a, b, names, options) => {
prefix = options.prefix; prefix = options.prefix;
defaultConfig = options.defaultConfig;
get(server, a, b, names); get(server, a, b, names);
list(server, a, b, names); list(server, a, b, names);
@ -38,7 +40,9 @@ export const get = (server, a, b, names) => {
}, include }); }, include });
reply(list); reply(list);
} },
config: defaultConfig
}) })
} }
@ -62,7 +66,9 @@ export const list = (server, a, b, names) => {
const list = await method({ where, include }); const list = await method({ where, include });
reply(list); reply(list);
} },
config: defaultConfig
}) })
} }
@ -94,14 +100,14 @@ export const scope = (server, a, b, names) => {
reply(list); reply(list);
}, },
config: { config: _.defaults({
validate: { validate: {
params: joi.object().keys({ params: joi.object().keys({
scope: joi.string().valid(...scopes), scope: joi.string().valid(...scopes),
aid: joi.number().integer().required() aid: joi.number().integer().required()
}) })
} }
} }, defaultConfig)
}) })
} }
@ -130,14 +136,14 @@ export const scopeScope = (server, a, b, names) => {
reply(list); reply(list);
}, },
config: { config: _.defaults({
validate: { validate: {
params: joi.object().keys({ params: joi.object().keys({
scopea: joi.string().valid(...scopes.a), scopea: joi.string().valid(...scopes.a),
scopeb: joi.string().valid(...scopes.b) scopeb: joi.string().valid(...scopes.b)
}) })
} }
} }, defaultConfig)
}) })
} }
@ -199,14 +205,14 @@ export const destroyScope = (server, a, b, names) => {
reply(list); reply(list);
}, },
config: { config: _.defaults({
validate: { validate: {
params: joi.object().keys({ params: joi.object().keys({
scope: joi.string().valid(...scopes), scope: joi.string().valid(...scopes),
aid: joi.number().integer().required() aid: joi.number().integer().required()
}) })
} }
} }, defaultConfig)
}); });
} }
@ -232,6 +238,8 @@ export const update = (server, a, b, names) => {
await* list.map(instance => instance.update(request.payload)); await* list.map(instance => instance.update(request.payload));
reply(list); reply(list);
} },
config: defaultConfig
}) })
} }

View File

@ -4,9 +4,11 @@ import _ from 'lodash';
import { parseInclude, parseWhere, getMethod } from '../utils'; import { parseInclude, parseWhere, getMethod } from '../utils';
let prefix; let prefix;
let defaultConfig;
export default (server, a, b, names, options) => { export default (server, a, b, names, options) => {
prefix = options.prefix; prefix = options.prefix;
defaultConfig = options.defaultConfig;
get(server, a, b, names); get(server, a, b, names);
create(server, a, b, names); create(server, a, b, names);
@ -38,7 +40,9 @@ export const get = (server, a, b, names) => {
} else { } else {
reply(list); reply(list);
} }
} },
config: defaultConfig
}) })
} }
@ -59,7 +63,9 @@ export const create = (server, a, b, names) => {
const instance = await method(request.payload); const instance = await method(request.payload);
reply(instance); reply(instance);
} },
config: defaultConfig
}) })
} }
@ -84,7 +90,9 @@ export const destroy = (server, a, b, names) => {
await instance.destroy(); await instance.destroy();
reply(instance); reply(instance);
} },
config: defaultConfig
}) })
} }
@ -110,6 +118,8 @@ export const update = (server, a, b, names) => {
await instance.update(request.payload); await instance.update(request.payload);
reply(instance); reply(instance);
} },
config: defaultConfig
}) })
} }

View File

@ -4,9 +4,11 @@ import _ from 'lodash';
import { parseInclude, parseWhere } from './utils'; import { parseInclude, parseWhere } from './utils';
let prefix; let prefix;
let defaultConfig;
export default (server, model, options) => { export default (server, model, options) => {
prefix = options.prefix; prefix = options.prefix;
defaultConfig = options.defaultConfig;
list(server, model); list(server, model);
get(server, model); get(server, model);
@ -33,7 +35,9 @@ export const list = (server, model) => {
}); });
reply(list); reply(list);
} },
config: defaultConfig
}); });
} }
@ -52,13 +56,13 @@ export const get = (server, model) => {
reply(instance); reply(instance);
}, },
config: { config: _.defaults({
validate: { validate: {
params: joi.object().keys({ params: joi.object().keys({
id: joi.number().integer() id: joi.number().integer()
}) })
} }
} }, defaultConfig)
}) })
} }
@ -78,13 +82,13 @@ export const scope = (server, model) => {
reply(list); reply(list);
}, },
config: { config: _.defaults({
validate: { validate: {
params: joi.object().keys({ params: joi.object().keys({
scope: joi.string().valid(...scopes) scope: joi.string().valid(...scopes)
}) })
} }
} }, defaultConfig)
}); });
} }
@ -98,7 +102,9 @@ export const create = (server, model) => {
const instance = await model.create(request.payload); const instance = await model.create(request.payload);
reply(instance); reply(instance);
} },
config: defaultConfig
}) })
} }
@ -118,7 +124,9 @@ export const destroy = (server, model) => {
await* list.map(instance => instance.destroy()); await* list.map(instance => instance.destroy());
reply(list.length === 1 ? list[0] : list); reply(list.length === 1 ? list[0] : list);
} },
config: defaultConfig
}) })
} }
@ -137,7 +145,9 @@ export const destroyAll = (server, model) => {
await* list.map(instance => instance.destroy()); await* list.map(instance => instance.destroy());
reply(list.length === 1 ? list[0] : list); reply(list.length === 1 ? list[0] : list);
} },
config: defaultConfig
}) })
} }
@ -159,13 +169,13 @@ export const destroyScope = (server, model) => {
reply(list); reply(list);
}, },
config: { config: _.defaults({
validate: { validate: {
params: joi.object().keys({ params: joi.object().keys({
scope: joi.string().valid(...scopes) scope: joi.string().valid(...scopes)
}) })
} }
} }, defaultConfig)
}); });
} }
@ -185,7 +195,9 @@ export const update = (server, model) => {
await instance.update(request.payload); await instance.update(request.payload);
reply(instance); reply(instance);
} },
config: defaultConfig
}) })
} }