mirror of
https://github.com/strapi/strapi.git
synced 2025-09-09 08:39:45 +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;
|
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) {
|
async find(opts, uid) {
|
||||||
const params = { ...opts, populate: getDeepPopulate(uid) };
|
const params = { ...opts, populate: getDeepPopulate(uid) };
|
||||||
|
|
||||||
const entities = await strapi.entityService.findMany(uid, params);
|
const entities = await strapi.entityService.findMany(uid, params);
|
||||||
|
|
||||||
if (!entities) {
|
return this.mapEntitesResponse(entities, uid);
|
||||||
return entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mappedResults = await mapAsync(entities.results || [entities], (entity) =>
|
|
||||||
this.mapEntity(entity, uid)
|
|
||||||
);
|
|
||||||
return { ...entities, results: mappedResults };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async findPage(opts, uid) {
|
async findPage(opts, uid) {
|
||||||
@ -103,14 +113,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
|
|
||||||
const entities = await strapi.entityService.findPage(uid, params);
|
const entities = await strapi.entityService.findPage(uid, params);
|
||||||
|
|
||||||
if (!entities) {
|
return this.mapEntitesResponse(entities, uid);
|
||||||
return entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mappedResults = await mapAsync(entities.results || [entities], (entity) =>
|
|
||||||
this.mapEntity(entity, uid)
|
|
||||||
);
|
|
||||||
return { ...entities, results: mappedResults };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async findWithRelationCountsPage(opts, uid) {
|
async findWithRelationCountsPage(opts, uid) {
|
||||||
@ -119,14 +122,7 @@ module.exports = ({ strapi }) => ({
|
|||||||
|
|
||||||
const entities = await strapi.entityService.findWithRelationCountsPage(uid, params);
|
const entities = await strapi.entityService.findWithRelationCountsPage(uid, params);
|
||||||
|
|
||||||
if (!entities) {
|
return this.mapEntitesResponse(entities, uid);
|
||||||
return entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mappedResults = await mapAsync(entities.results || [entities], (entity) =>
|
|
||||||
this.mapEntity(entity, uid)
|
|
||||||
);
|
|
||||||
return { ...entities, results: mappedResults };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async findOneWithCreatorRolesAndCount(id, uid) {
|
async findOneWithCreatorRolesAndCount(id, uid) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user