mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 08:38:09 +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) {
|
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);
|
return strapi.query('file', 'upload').find(params);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -12,9 +12,7 @@ const _ = require('lodash');
|
|||||||
const convertRestQueryParams = (params = {}, defaults = {}) => {
|
const convertRestQueryParams = (params = {}, defaults = {}) => {
|
||||||
if (typeof params !== 'object' || params === null) {
|
if (typeof params !== 'object' || params === null) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`convertRestQueryParams expected an object got ${
|
`convertRestQueryParams expected an object got ${params === null ? 'null' : typeof params}`
|
||||||
params === null ? 'null' : typeof params
|
|
||||||
}`
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,12 +34,18 @@ const convertRestQueryParams = (params = {}, defaults = {}) => {
|
|||||||
Object.assign(finalParams, convertLimitQueryParams(params._limit));
|
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)
|
if (_.keys(whereParams).length > 0) {
|
||||||
Object.assign(finalParams, {
|
whereClauses.push(...convertWhereParams(whereParams));
|
||||||
where: convertWhereParams(whereParams),
|
}
|
||||||
});
|
|
||||||
|
if (_.has(params, '_where')) {
|
||||||
|
whereClauses.push(...convertWhereParams(params._where));
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(finalParams, { where: whereClauses });
|
||||||
|
|
||||||
return finalParams;
|
return finalParams;
|
||||||
};
|
};
|
||||||
@ -52,9 +56,7 @@ const convertRestQueryParams = (params = {}, defaults = {}) => {
|
|||||||
*/
|
*/
|
||||||
const convertSortQueryParams = sortQuery => {
|
const convertSortQueryParams = sortQuery => {
|
||||||
if (typeof sortQuery !== 'string') {
|
if (typeof sortQuery !== 'string') {
|
||||||
throw new Error(
|
throw new Error(`convertSortQueryParams expected a string, got ${typeof sortQuery}`);
|
||||||
`convertSortQueryParams expected a string, got ${typeof sortQuery}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortKeys = [];
|
const sortKeys = [];
|
||||||
@ -87,9 +89,7 @@ const convertStartQueryParams = startQuery => {
|
|||||||
const startAsANumber = _.toNumber(startQuery);
|
const startAsANumber = _.toNumber(startQuery);
|
||||||
|
|
||||||
if (!_.isInteger(startAsANumber) || startAsANumber < 0) {
|
if (!_.isInteger(startAsANumber) || startAsANumber < 0) {
|
||||||
throw new Error(
|
throw new Error(`convertStartQueryParams expected a positive integer got ${startAsANumber}`);
|
||||||
`convertStartQueryParams expected a positive integer got ${startAsANumber}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -104,13 +104,8 @@ const convertStartQueryParams = startQuery => {
|
|||||||
const convertLimitQueryParams = limitQuery => {
|
const convertLimitQueryParams = limitQuery => {
|
||||||
const limitAsANumber = _.toNumber(limitQuery);
|
const limitAsANumber = _.toNumber(limitQuery);
|
||||||
|
|
||||||
if (
|
if (!_.isInteger(limitAsANumber) || (limitAsANumber !== -1 && limitAsANumber < 0)) {
|
||||||
!_.isInteger(limitAsANumber) ||
|
throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`);
|
||||||
(limitAsANumber !== -1 && limitAsANumber < 0)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -141,6 +136,12 @@ const VALID_OPERATORS = [
|
|||||||
const convertWhereParams = whereParams => {
|
const convertWhereParams = whereParams => {
|
||||||
let finalWhere = [];
|
let finalWhere = [];
|
||||||
|
|
||||||
|
if (Array.isArray(whereParams)) {
|
||||||
|
return whereParams.reduce((acc, whereParam) => {
|
||||||
|
return acc.concat(convertWhereParams(whereParam));
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
Object.keys(whereParams).forEach(whereClause => {
|
Object.keys(whereParams).forEach(whereClause => {
|
||||||
const { field, operator = 'eq', value } = convertWhereClause(
|
const { field, operator = 'eq', value } = convertWhereClause(
|
||||||
whereClause,
|
whereClause,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user