Skip to content

Commit

Permalink
fix: using ?include is not working with multiple resources (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed May 21, 2016
1 parent ef8e779 commit 6d97ca7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/packages/controller/middleware/sanitize-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { camelize } from 'inflection';

import pick from '../../../utils/pick';

const { isArray } = Array;
const { entries, assign } = Object;

export default function sanitizeParams(req, res) {
const { modelName } = this;
const { modelName, model: { relationshipNames } } = this;
const params = { ...req.params };
let { page, limit, sort, filter, include, fields } = params;

Expand Down Expand Up @@ -43,7 +44,9 @@ export default function sanitizeParams(req, res) {
}

if (!include || typeof include !== 'string') {
include = [];
if (!isArray(include)) {
include = [];
}
} else {
if (include.indexOf(',') >= 0) {
include = include.split(',');
Expand All @@ -52,6 +55,9 @@ export default function sanitizeParams(req, res) {
}
}

include = include
.filter(included => relationshipNames.indexOf(included) >= 0);

fields = entries(fields || {})
.reduce((obj, [key, value]) => {
if (typeof value === 'string') {
Expand Down

0 comments on commit 6d97ca7

Please sign in to comment.