mirror of
https://github.com/strapi/strapi.git
synced 2025-09-08 08:08:18 +00:00
chore(content-manager): PR feedback
This commit is contained in:
parent
de5d6b5a8c
commit
7da22885ad
@ -83,19 +83,29 @@ module.exports = ({ strapi }) => ({
|
||||
return entity;
|
||||
},
|
||||
|
||||
/**
|
||||
* Some entity manager functions may return multiple entites or one entity.
|
||||
* This function maps the response in both cases
|
||||
* @param {Array|Object|null} entities
|
||||
* @param {string} uid
|
||||
*/
|
||||
async mapEntitesResponse(entities, uid) {
|
||||
if (entities?.results) {
|
||||
const mappedResults = await mapAsync(entities.results, (entity) =>
|
||||
this.mapEntity(entity, uid)
|
||||
);
|
||||
return { ...entities, results: mappedResults };
|
||||
}
|
||||
// if entity is single type
|
||||
return this.mapEntity(entities, uid);
|
||||
},
|
||||
|
||||
async find(opts, uid) {
|
||||
const params = { ...opts, populate: getDeepPopulate(uid) };
|
||||
|
||||
const entities = await strapi.entityService.findMany(uid, params);
|
||||
|
||||
if (!entities) {
|
||||
return entities;
|
||||
}
|
||||
|
||||
const mappedResults = await mapAsync(entities.results || [entities], (entity) =>
|
||||
this.mapEntity(entity, uid)
|
||||
);
|
||||
return { ...entities, results: mappedResults };
|
||||
return this.mapEntitesResponse(entities, uid);
|
||||
},
|
||||
|
||||
async findPage(opts, uid) {
|
||||
@ -103,14 +113,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const entities = await strapi.entityService.findPage(uid, params);
|
||||
|
||||
if (!entities) {
|
||||
return entities;
|
||||
}
|
||||
|
||||
const mappedResults = await mapAsync(entities.results || [entities], (entity) =>
|
||||
this.mapEntity(entity, uid)
|
||||
);
|
||||
return { ...entities, results: mappedResults };
|
||||
return this.mapEntitesResponse(entities, uid);
|
||||
},
|
||||
|
||||
async findWithRelationCountsPage(opts, uid) {
|
||||
@ -119,14 +122,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const entities = await strapi.entityService.findWithRelationCountsPage(uid, params);
|
||||
|
||||
if (!entities) {
|
||||
return entities;
|
||||
}
|
||||
|
||||
const mappedResults = await mapAsync(entities.results || [entities], (entity) =>
|
||||
this.mapEntity(entity, uid)
|
||||
);
|
||||
return { ...entities, results: mappedResults };
|
||||
return this.mapEntitesResponse(entities, uid);
|
||||
},
|
||||
|
||||
async findOneWithCreatorRolesAndCount(id, uid) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user