mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 06:35:47 +00:00
Move hasDeepFilters to utils
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
c8d743ef60
commit
966d9c554f
@ -138,7 +138,7 @@ const buildJoinsAndFilter = (qb, model, whereClauses) => {
|
||||
};
|
||||
};
|
||||
|
||||
// tree made to create the joins strucutre
|
||||
// tree made to create the joins structure
|
||||
const tree = {
|
||||
alias: model.collectionName,
|
||||
assoc: null,
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
const _ = require('lodash');
|
||||
var semver = require('semver');
|
||||
const utils = require('./utils')();
|
||||
const { hasDeepFilters } = require('strapi-utils');
|
||||
|
||||
const combineSearchAndWhere = (search = [], wheres = []) => {
|
||||
const criterias = {};
|
||||
@ -64,18 +65,6 @@ const buildSearchOr = (model, query) => {
|
||||
|
||||
const BOOLEAN_OPERATORS = ['or'];
|
||||
|
||||
const hasDeepFilters = (whereClauses = []) => {
|
||||
return (
|
||||
whereClauses.filter(({ field, operator, value }) => {
|
||||
if (BOOLEAN_OPERATORS.includes(operator)) {
|
||||
return value.filter(hasDeepFilters).length > 0;
|
||||
}
|
||||
|
||||
return field.split('.').length > 1;
|
||||
}).length > 0
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a mongo query
|
||||
* @param {Object} options - Query options
|
||||
|
||||
@ -90,7 +90,7 @@ const normalizeFieldName = ({ model, field }) => {
|
||||
|
||||
const BOOLEAN_OPERATORS = ['or'];
|
||||
|
||||
const hasDeepFilters = whereClauses => {
|
||||
const hasDeepFilters = (whereClauses = []) => {
|
||||
return (
|
||||
whereClauses.filter(({ field, operator, value }) => {
|
||||
if (BOOLEAN_OPERATORS.includes(operator)) {
|
||||
@ -156,4 +156,7 @@ const buildQuery = ({ model, filters = {}, ...rest }) => {
|
||||
return strapi.db.connectors.get(model.orm).buildQuery({ model, filters, ...rest });
|
||||
};
|
||||
|
||||
module.exports = buildQuery;
|
||||
module.exports = {
|
||||
buildQuery,
|
||||
hasDeepFilters,
|
||||
};
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* Export shared utilities
|
||||
*/
|
||||
const convertRestQueryParams = require('./convert-rest-query-params');
|
||||
const buildQuery = require('./build-query');
|
||||
const { buildQuery, hasDeepFilters } = require('./build-query');
|
||||
const parseMultipartData = require('./parse-multipart');
|
||||
const sanitizeEntity = require('./sanitize-entity');
|
||||
const parseType = require('./parse-type');
|
||||
@ -36,6 +36,7 @@ module.exports = {
|
||||
templateConfiguration,
|
||||
convertRestQueryParams,
|
||||
buildQuery,
|
||||
hasDeepFilters,
|
||||
parseMultipartData,
|
||||
sanitizeEntity,
|
||||
parseType,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user