Validate query and payload #20
@ -102,6 +102,8 @@ export const get = ({ server, model, prefix = '/', config }) => {
|
||||
const { id } = request.params;
|
||||
if (id) where[model.primaryKeyField] = id;
|
||||
|
||||
if (include instanceof Error) return void reply(include);
|
||||
|
||||
const instance = await model.findOne({ where, include });
|
||||
|
||||
if (!instance) return void reply(notFound(`${id} not found.`));
|
||||
@ -130,6 +132,8 @@ export const scope = ({ server, model, prefix = '/', config }) => {
|
||||
const include = parseInclude(request);
|
||||
const where = parseWhere(request);
|
||||
|
||||
if (include instanceof Error) return void reply(include);
|
||||
|
||||
const list = await model.scope(request.params.scope).findAll({ include, where });
|
||||
|
||||
reply(list);
|
||||
@ -213,6 +217,8 @@ export const destroyScope = ({ server, model, prefix = '/', config }) => {
|
||||
const include = parseInclude(request);
|
||||
const where = parseWhere(request);
|
||||
|
||||
if (include instanceof Error) return void reply(include);
|
||||
|
||||
const list = await model.scope(request.params.scope).findAll({ include, where });
|
||||
|
||||
await Promise.all(list.map(instance => instance.destroy()));
|
||||
|
Loading…
Reference in New Issue
Block a user