mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
Refactor combineFilters
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
dc28c0e921
commit
6f1f774146
@ -21,6 +21,14 @@ const generateFileName = name => {
|
|||||||
return `${baseName}_${randomSuffix()}`;
|
return `${baseName}_${randomSuffix()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const combineFilters = 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
|
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
|
||||||
const ext = path.extname(filename);
|
const ext = path.extname(filename);
|
||||||
@ -250,12 +258,7 @@ 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
|
combineFilters(params);
|
||||||
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -268,12 +271,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
count(params) {
|
count(params) {
|
||||||
// FIXME: until we support boolean operators for querying we need to make mime_ncontains use AND instead of OR
|
combineFilters(params);
|
||||||
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').count(params);
|
return strapi.query('file', 'upload').count(params);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user