mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 07:10:11 +00:00
feature: populate from query
This commit is contained in:
parent
7c0a562948
commit
a9efdd0771
@ -23,7 +23,7 @@ module.exports = {
|
|||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const populate = await populateBuilder(model)
|
||||||
.populateDeep(1)
|
.populateDeep(1)
|
||||||
.countRelations({ toMany: true, toOne: false })
|
.countRelations({ toOne: false })
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const { results, pagination } = await entityManager.findPage(
|
const { results, pagination } = await entityManager.findPage(
|
||||||
@ -52,10 +52,11 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const permissionQuery = await permissionChecker.sanitizedQuery.read(ctx.query);
|
||||||
const populate = await populateBuilder(model)
|
const populate = await populateBuilder(model)
|
||||||
.populateRequiredPermissions(permissionChecker, ctx.query)
|
.populateFromQuery(permissionQuery)
|
||||||
.populateDeep(Infinity)
|
.populateDeep(Infinity)
|
||||||
.countRelations({ toMany: true, toOne: true })
|
.countRelations()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const entity = await entityManager.findOne(id, model, { populate });
|
const entity = await entityManager.findOne(id, model, { populate });
|
||||||
@ -69,7 +70,7 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move the transform relations to count here.
|
// TODO: Count populated relations by permissions
|
||||||
|
|
||||||
ctx.body = await permissionChecker.sanitizeOutput(entity);
|
ctx.body = await permissionChecker.sanitizeOutput(entity);
|
||||||
},
|
},
|
||||||
@ -96,13 +97,7 @@ module.exports = {
|
|||||||
|
|
||||||
const sanitizedBody = await sanitizeFn(body);
|
const sanitizedBody = await sanitizeFn(body);
|
||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const entity = await entityManager.create(sanitizedBody, model);
|
||||||
.populateDeep(Infinity)
|
|
||||||
// TODO: Use config to know if we need to count relations or not
|
|
||||||
.countRelations({ toMany: true, toOne: true })
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const entity = await entityManager.create(sanitizedBody, model, { populate });
|
|
||||||
|
|
||||||
ctx.body = await permissionChecker.sanitizeOutput(entity);
|
ctx.body = await permissionChecker.sanitizeOutput(entity);
|
||||||
|
|
||||||
@ -125,9 +120,8 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const permissionQuery = await permissionChecker.sanitizedQuery.update(ctx.query);
|
||||||
.populateRequiredPermissions(permissionChecker, ctx.query)
|
const populate = await populateBuilder(model).populateFromQuery(permissionQuery).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
const entity = await entityManager.findOne(id, model, { populate });
|
const entity = await entityManager.findOne(id, model, { populate });
|
||||||
|
|
||||||
@ -145,15 +139,7 @@ module.exports = {
|
|||||||
const sanitizeFn = pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
const sanitizeFn = pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||||
const sanitizedBody = await sanitizeFn(body);
|
const sanitizedBody = await sanitizeFn(body);
|
||||||
|
|
||||||
const populateUpdate = await populateBuilder(model)
|
const updatedEntity = await entityManager.update(entity, sanitizedBody, model);
|
||||||
.populateDeep(Infinity)
|
|
||||||
// TODO: Use config to know if we need to count relations or not
|
|
||||||
.countRelations({ toMany: true, toOne: true })
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const updatedEntity = await entityManager.update(entity, sanitizedBody, model, {
|
|
||||||
populate: populateUpdate,
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.body = await permissionChecker.sanitizeOutput(updatedEntity);
|
ctx.body = await permissionChecker.sanitizeOutput(updatedEntity);
|
||||||
},
|
},
|
||||||
@ -169,9 +155,8 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const permissionQuery = await permissionChecker.sanitizedQuery.delete(ctx.query);
|
||||||
.populateRequiredPermissions(permissionChecker, ctx.query)
|
const populate = await populateBuilder(model).populateFromQuery(permissionQuery).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
const entity = await entityManager.findOne(id, model, { populate });
|
const entity = await entityManager.findOne(id, model, { populate });
|
||||||
|
|
||||||
@ -183,13 +168,7 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populateDelete = await populateBuilder(model)
|
const result = await entityManager.delete(entity, model);
|
||||||
.populateDeep(Infinity)
|
|
||||||
// TODO: Use config to know if we need to count relations or not
|
|
||||||
.countRelations({ toMany: true, toOne: true })
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const result = await entityManager.delete(entity, model, { populate: populateDelete });
|
|
||||||
|
|
||||||
// TODO: Count if config was enabled or populate based on permissions is not empty
|
// TODO: Count if config was enabled or populate based on permissions is not empty
|
||||||
|
|
||||||
@ -207,9 +186,8 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const permissionQuery = await permissionChecker.sanitizedQuery.publish(ctx.query);
|
||||||
.populateRequiredPermissions(permissionChecker, ctx.query)
|
const populate = await populateBuilder(model).populateFromQuery(permissionQuery).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
const entity = await entityManager.findOne(id, model, { populate });
|
const entity = await entityManager.findOne(id, model, { populate });
|
||||||
|
|
||||||
@ -221,16 +199,10 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populatePublish = await populateBuilder(model)
|
|
||||||
.populateDeep(Infinity)
|
|
||||||
.countRelations({ toMany: true, toOne: true })
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const result = await entityManager.publish(
|
const result = await entityManager.publish(
|
||||||
entity,
|
entity,
|
||||||
setCreatorFields({ user, isEdition: true })({}),
|
setCreatorFields({ user, isEdition: true })({}),
|
||||||
model,
|
model
|
||||||
{ populate: populatePublish }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.body = await permissionChecker.sanitizeOutput(result);
|
ctx.body = await permissionChecker.sanitizeOutput(result);
|
||||||
@ -247,9 +219,8 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const permissionQuery = await permissionChecker.sanitizedQuery.unpublish(ctx.query);
|
||||||
.populateRequiredPermissions(permissionChecker, ctx.query)
|
const populate = await populateBuilder(model).populateFromQuery(permissionQuery).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
const entity = await entityManager.findOne(id, model, { populate });
|
const entity = await entityManager.findOne(id, model, { populate });
|
||||||
|
|
||||||
@ -261,16 +232,10 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populateUnpublish = await populateBuilder(model)
|
|
||||||
.populateDeep(Infinity)
|
|
||||||
.countRelations({ toMany: true, toOne: true })
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const result = await entityManager.unpublish(
|
const result = await entityManager.unpublish(
|
||||||
entity,
|
entity,
|
||||||
setCreatorFields({ user, isEdition: true })({}),
|
setCreatorFields({ user, isEdition: true })({}),
|
||||||
model,
|
model
|
||||||
{ populate: populateUnpublish }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.body = await permissionChecker.sanitizeOutput(result);
|
ctx.body = await permissionChecker.sanitizeOutput(result);
|
||||||
@ -318,9 +283,8 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const populate = await populateBuilder(model)
|
const permissionQuery = await permissionChecker.sanitizedQuery.read(ctx.query);
|
||||||
.populateRequiredPermissions(permissionChecker, ctx.query)
|
const populate = await populateBuilder(model).populateFromQuery(permissionQuery).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
const entity = await entityManager.findOne(id, model, { populate });
|
const entity = await entityManager.findOne(id, model, { populate });
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user