mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Treat mime ncontains as AND params in files list
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
72440af84b
commit
d19189b626
@ -233,6 +233,12 @@ module.exports = {
|
||||
},
|
||||
|
||||
fetchAll(params) {
|
||||
// FIXME: until we support boolean operators for querying we need to make mime_ncontains use AND instead of OR
|
||||
if (_.has(params, 'mime_ncontains') && Array.isArray(params.mime_ncontains)) {
|
||||
params._where = params.mime_ncontains.map(val => ({ mime_ncontains: val }));
|
||||
delete params.mime_ncontains;
|
||||
}
|
||||
|
||||
return strapi.query('file', 'upload').find(params);
|
||||
},
|
||||
|
||||
|
||||
@ -12,9 +12,7 @@ const _ = require('lodash');
|
||||
const convertRestQueryParams = (params = {}, defaults = {}) => {
|
||||
if (typeof params !== 'object' || params === null) {
|
||||
throw new Error(
|
||||
`convertRestQueryParams expected an object got ${
|
||||
params === null ? 'null' : typeof params
|
||||
}`
|
||||
`convertRestQueryParams expected an object got ${params === null ? 'null' : typeof params}`
|
||||
);
|
||||
}
|
||||
|
||||
@ -36,12 +34,18 @@ const convertRestQueryParams = (params = {}, defaults = {}) => {
|
||||
Object.assign(finalParams, convertLimitQueryParams(params._limit));
|
||||
}
|
||||
|
||||
const whereParams = _.omit(params, ['_sort', '_start', '_limit']);
|
||||
const whereParams = _.omit(params, ['_sort', '_start', '_limit', '_where']);
|
||||
const whereClauses = [];
|
||||
|
||||
if (_.keys(whereParams).length > 0)
|
||||
Object.assign(finalParams, {
|
||||
where: convertWhereParams(whereParams),
|
||||
});
|
||||
if (_.keys(whereParams).length > 0) {
|
||||
whereClauses.push(...convertWhereParams(whereParams));
|
||||
}
|
||||
|
||||
if (_.has(params, '_where')) {
|
||||
whereClauses.push(...convertWhereParams(params._where));
|
||||
}
|
||||
|
||||
Object.assign(finalParams, { where: whereClauses });
|
||||
|
||||
return finalParams;
|
||||
};
|
||||
@ -52,9 +56,7 @@ const convertRestQueryParams = (params = {}, defaults = {}) => {
|
||||
*/
|
||||
const convertSortQueryParams = sortQuery => {
|
||||
if (typeof sortQuery !== 'string') {
|
||||
throw new Error(
|
||||
`convertSortQueryParams expected a string, got ${typeof sortQuery}`
|
||||
);
|
||||
throw new Error(`convertSortQueryParams expected a string, got ${typeof sortQuery}`);
|
||||
}
|
||||
|
||||
const sortKeys = [];
|
||||
@ -87,9 +89,7 @@ const convertStartQueryParams = startQuery => {
|
||||
const startAsANumber = _.toNumber(startQuery);
|
||||
|
||||
if (!_.isInteger(startAsANumber) || startAsANumber < 0) {
|
||||
throw new Error(
|
||||
`convertStartQueryParams expected a positive integer got ${startAsANumber}`
|
||||
);
|
||||
throw new Error(`convertStartQueryParams expected a positive integer got ${startAsANumber}`);
|
||||
}
|
||||
|
||||
return {
|
||||
@ -104,13 +104,8 @@ const convertStartQueryParams = startQuery => {
|
||||
const convertLimitQueryParams = limitQuery => {
|
||||
const limitAsANumber = _.toNumber(limitQuery);
|
||||
|
||||
if (
|
||||
!_.isInteger(limitAsANumber) ||
|
||||
(limitAsANumber !== -1 && limitAsANumber < 0)
|
||||
) {
|
||||
throw new Error(
|
||||
`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`
|
||||
);
|
||||
if (!_.isInteger(limitAsANumber) || (limitAsANumber !== -1 && limitAsANumber < 0)) {
|
||||
throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`);
|
||||
}
|
||||
|
||||
return {
|
||||
@ -141,6 +136,12 @@ const VALID_OPERATORS = [
|
||||
const convertWhereParams = whereParams => {
|
||||
let finalWhere = [];
|
||||
|
||||
if (Array.isArray(whereParams)) {
|
||||
return whereParams.reduce((acc, whereParam) => {
|
||||
return acc.concat(convertWhereParams(whereParam));
|
||||
}, []);
|
||||
}
|
||||
|
||||
Object.keys(whereParams).forEach(whereClause => {
|
||||
const { field, operator = 'eq', value } = convertWhereClause(
|
||||
whereClause,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user