Add feature to allow nested include and filtering relationships/associations #36
10
src/utils.js
10
src/utils.js
@ -1,5 +1,6 @@
|
|||||||
import { omit, identity, toNumber, isString, isUndefined } from 'lodash';
|
import { omit, identity, toNumber, isString, isUndefined } from 'lodash';
|
||||||
import { notImplemented } from 'boom';
|
import { notImplemented } from 'boom';
|
||||||
|
import joi from 'joi';
|
||||||
|
|
||||||
const sequelizeKeys = ['include', 'order', 'limit', 'offset'];
|
const sequelizeKeys = ['include', 'order', 'limit', 'offset'];
|
||||||
|
|
||||||
@ -26,7 +27,14 @@ export const parseInclude = request => {
|
|||||||
if (models.isBoom) return models;
|
if (models.isBoom) return models;
|
||||||
|
|
||||||
return include.map(b => {
|
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') {
|
if (typeof a !== 'object') {
|
||||||
const singluarOrPluralMatch = Object.keys(models).find((modelName) => {
|
const singluarOrPluralMatch = Object.keys(models).find((modelName) => {
|
||||||
const { _singular, _plural } = models[modelName];
|
const { _singular, _plural } = models[modelName];
|
||||||
|
Loading…
Reference in New Issue
Block a user