Fix: handle all parseInclude
errors
This commit is contained in:
parent
bd18c57529
commit
e0132c2cae
@ -102,6 +102,8 @@ export const get = ({ server, model, prefix = '/', config }) => {
|
|||||||
const { id } = request.params;
|
const { id } = request.params;
|
||||||
if (id) where[model.primaryKeyField] = id;
|
if (id) where[model.primaryKeyField] = id;
|
||||||
|
|
||||||
|
if (include instanceof Error) return void reply(include);
|
||||||
|
|
||||||
const instance = await model.findOne({ where, include });
|
const instance = await model.findOne({ where, include });
|
||||||
|
|
||||||
if (!instance) return void reply(notFound(`${id} not found.`));
|
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 include = parseInclude(request);
|
||||||
const where = parseWhere(request);
|
const where = parseWhere(request);
|
||||||
|
|
||||||
|
if (include instanceof Error) return void reply(include);
|
||||||
|
|
||||||
const list = await model.scope(request.params.scope).findAll({ include, where });
|
const list = await model.scope(request.params.scope).findAll({ include, where });
|
||||||
|
|
||||||
reply(list);
|
reply(list);
|
||||||
@ -213,6 +217,8 @@ export const destroyScope = ({ server, model, prefix = '/', config }) => {
|
|||||||
const include = parseInclude(request);
|
const include = parseInclude(request);
|
||||||
const where = parseWhere(request);
|
const where = parseWhere(request);
|
||||||
|
|
||||||
|
if (include instanceof Error) return void reply(include);
|
||||||
|
|
||||||
const list = await model.scope(request.params.scope).findAll({ include, where });
|
const list = await model.scope(request.params.scope).findAll({ include, where });
|
||||||
|
|
||||||
await Promise.all(list.map(instance => instance.destroy()));
|
await Promise.all(list.map(instance => instance.destroy()));
|
||||||
|
Loading…
Reference in New Issue
Block a user