diff --git a/packages/strapi-admin/package.json b/packages/strapi-admin/package.json index d4d434105c..828ab83fa9 100644 --- a/packages/strapi-admin/package.json +++ b/packages/strapi-admin/package.json @@ -55,4 +55,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-hook-bookshelf/lib/buildQuery.js b/packages/strapi-hook-bookshelf/lib/buildQuery.js index d331d92696..bf3bf6d526 100644 --- a/packages/strapi-hook-bookshelf/lib/buildQuery.js +++ b/packages/strapi-hook-bookshelf/lib/buildQuery.js @@ -140,9 +140,9 @@ const buildQueryJoins = (qb, { model, where }) => { let tmpModel = model; for (let part of parts) { const association = tmpModel.associations.find(assoc => assoc.alias === part); - const assocModel = findModelByAssoc(association); if (association) { + const assocModel = findModelByAssoc(association); buildSingleJoin(qb, tmpModel, assocModel, association); tmpModel = assocModel; } diff --git a/packages/strapi-hook-mongoose/lib/buildQuery.js b/packages/strapi-hook-mongoose/lib/buildQuery.js index 85bb32c830..08edb2b68f 100644 --- a/packages/strapi-hook-mongoose/lib/buildQuery.js +++ b/packages/strapi-hook-mongoose/lib/buildQuery.js @@ -292,36 +292,55 @@ const buildQueryMatches = (model, filters) => { return []; }; +const formatValue = value => { + if (Array.isArray(value)) { + return value.map(formatValue); + } + + const number = _.toNumber(value); + if (_.isFinite(number)) return number; + + return utils.valueToId(value); +}; + const buildWhereClause = ({ field, operator, value }) => { + const val = formatValue(value); + + if (Array.isArray(val) && !['in', 'nin'].includes(operator)) { + return { + $or: val.map(value => buildWhereClause({ field, operator, value })), + }; + } + switch (operator) { case 'eq': - return { [field]: utils.valueToId(value) }; + return { [field]: val }; case 'ne': - return { [field]: { $ne: utils.valueToId(value) } }; + return { [field]: { $ne: val } }; case 'lt': - return { [field]: { $lt: value } }; + return { [field]: { $lt: val } }; case 'lte': - return { [field]: { $lte: value } }; + return { [field]: { $lte: val } }; case 'gt': - return { [field]: { $gt: value } }; + return { [field]: { $gt: val } }; case 'gte': - return { [field]: { $gte: value } }; + return { [field]: { $gte: val } }; case 'in': return { [field]: { - $in: Array.isArray(value) ? value.map(utils.valueToId) : [utils.valueToId(value)], + $in: Array.isArray(val) ? val : [val], }, }; case 'nin': return { [field]: { - $nin: Array.isArray(value) ? value.map(utils.valueToId) : [utils.valueToId(value)], + $nin: Array.isArray(val) ? val : [val], }, }; case 'contains': { return { [field]: { - $regex: value, + $regex: `${val}`, $options: 'i', }, }; @@ -329,19 +348,19 @@ const buildWhereClause = ({ field, operator, value }) => { case 'ncontains': return { [field]: { - $not: new RegExp(value, 'i'), + $not: new RegExp(val, 'i'), }, }; case 'containss': return { [field]: { - $regex: value, + $regex: `${val}`, }, }; case 'ncontainss': return { [field]: { - $not: new RegExp(value), + $not: new RegExp(val), }, }; diff --git a/packages/strapi-plugin-content-manager/package.json b/packages/strapi-plugin-content-manager/package.json index f437e1f774..9dc6e2db19 100644 --- a/packages/strapi-plugin-content-manager/package.json +++ b/packages/strapi-plugin-content-manager/package.json @@ -53,4 +53,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-content-type-builder/package.json b/packages/strapi-plugin-content-type-builder/package.json index e3e83d4d28..d8945718e8 100644 --- a/packages/strapi-plugin-content-type-builder/package.json +++ b/packages/strapi-plugin-content-type-builder/package.json @@ -51,4 +51,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-email/package.json b/packages/strapi-plugin-email/package.json index 3794208763..39f7b528fd 100644 --- a/packages/strapi-plugin-email/package.json +++ b/packages/strapi-plugin-email/package.json @@ -51,4 +51,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-graphql/package.json b/packages/strapi-plugin-graphql/package.json index 648c88d399..652920f3ce 100644 --- a/packages/strapi-plugin-graphql/package.json +++ b/packages/strapi-plugin-graphql/package.json @@ -54,4 +54,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-settings-manager/package.json b/packages/strapi-plugin-settings-manager/package.json index e6ad03ef0d..14e6210081 100644 --- a/packages/strapi-plugin-settings-manager/package.json +++ b/packages/strapi-plugin-settings-manager/package.json @@ -53,4 +53,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-upload/package.json b/packages/strapi-plugin-upload/package.json index c64b3c697a..bc62da0316 100644 --- a/packages/strapi-plugin-upload/package.json +++ b/packages/strapi-plugin-upload/package.json @@ -47,4 +47,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-users-permissions/package.json b/packages/strapi-plugin-users-permissions/package.json index fdf4ca0c25..8c80835e8f 100644 --- a/packages/strapi-plugin-users-permissions/package.json +++ b/packages/strapi-plugin-users-permissions/package.json @@ -56,4 +56,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-utils/lib/convertQueryParams/convertRestQueryParams.js b/packages/strapi-utils/lib/convertQueryParams/convertRestQueryParams.js index 40be1f2af8..12b5abeeb3 100644 --- a/packages/strapi-utils/lib/convertQueryParams/convertRestQueryParams.js +++ b/packages/strapi-utils/lib/convertQueryParams/convertRestQueryParams.js @@ -88,7 +88,7 @@ const convertStartQueryParams = startQuery => { const startAsANumber = _.toNumber(startQuery); if (!_.isInteger(startAsANumber) || startAsANumber < 0) { - throw new Error(`convertStartQueryParams expected a positive integer go ${startAsANumber}`); + throw new Error(`convertStartQueryParams expected a positive integer got ${startAsANumber}`); } return { @@ -104,7 +104,7 @@ const convertLimitQueryParams = limitQuery => { const limitAsANumber = _.toNumber(limitQuery); if (!_.isInteger(limitAsANumber) || (limitAsANumber !== -1 && limitAsANumber < 0)) { - throw new Error(`convertLimitQueryParams expected a positive integer go ${limitAsANumber}`); + throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`); } return {