refactor DZ populate for better clarity

This commit is contained in:
Pierre Noël 2022-08-29 16:15:09 +02:00
parent 6c4039e3f1
commit b17d1001c8

View File

@ -6,16 +6,7 @@
* Converts the standard Strapi REST query params to a more usable format for querying * Converts the standard Strapi REST query params to a more usable format for querying
* You can read more here: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html#filters * You can read more here: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html#filters
*/ */
const { const { has, isEmpty, isObject, isPlainObject, cloneDeep, get, mergeAll } = require('lodash/fp');
has,
isEmpty,
isObject,
isPlainObject,
cloneDeep,
get,
mergeAll,
isBoolean,
} = require('lodash/fp');
const _ = require('lodash'); const _ = require('lodash');
const parseType = require('./parse-type'); const parseType = require('./parse-type');
const contentTypesUtils = require('./content-types'); const contentTypesUtils = require('./content-types');
@ -183,10 +174,8 @@ const convertPopulateObject = (populate, schema) => {
if (attribute.type === 'dynamiczone') { if (attribute.type === 'dynamiczone') {
const populates = attribute.components const populates = attribute.components
.map((uid) => strapi.getModel(uid)) .map((uid) => strapi.getModel(uid))
.map((schema) => { .map((schema) => convertNestedPopulate(subPopulate, schema))
const populate = convertNestedPopulate(subPopulate, schema); .map((populate) => (populate === true ? {} : populate)) // cast boolean to empty object to avoid merging issues
return isBoolean(populate) && populate ? {} : populate;
})
.filter((populate) => populate !== false); .filter((populate) => populate !== false);
if (isEmpty(populates)) { if (isEmpty(populates)) {