Added try catch block and JSON validation logic of relationship/association parser
This commit is contained in:
parent
11306667d6
commit
49d24ea265
10
src/utils.js
10
src/utils.js
@ -1,5 +1,6 @@
|
||||
import { omit, identity, toNumber, isString, isUndefined } from 'lodash';
|
||||
import { notImplemented } from 'boom';
|
||||
import joi from 'joi';
|
||||
|
||||
const sequelizeKeys = ['include', 'order', 'limit', 'offset'];
|
||||
|
||||
@ -26,7 +27,14 @@ export const parseInclude = request => {
|
||||
if (models.isBoom) return models;
|
||||
|
||||
return include.map(b => {
|
||||
const a = /^{.*}$/.test(b) ? JSON.parse(b) : b;
|
||||
let a = b;
|
||||
try {
|
||||
if (joi.string().regex(/^\{.*?"model":.*?\}$/)) {
|
||||
a = JSON.parse(b);
|
||||
}
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
if (typeof a !== 'object') {
|
||||
const singluarOrPluralMatch = Object.keys(models).find((modelName) => {
|
||||
const { _singular, _plural } = models[modelName];
|
||||
|
Loading…
Reference in New Issue
Block a user