Added try catch block and JSON validation logic of relationship/association parser

This commit is contained in:
Muhammad Labib Ramadhan 2016-11-08 08:23:37 +07:00
parent 11306667d6
commit 49d24ea265

View File

@ -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];