Add feature to allow nested include and filtering relationships/associations #36

Open
labibramadhan wants to merge 8 commits from labibramadhan/include-with-filter into master
Showing only changes of commit 49d24ea265 - Show all commits

View File

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