Add single type usecase and fix delete

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-07-02 16:40:40 +02:00
parent 44a7e2321d
commit 3ff5f645c8
2 changed files with 15 additions and 3 deletions

View File

@ -84,7 +84,19 @@ module.exports = {
const method = _.has(request.query, '_q') ? 'search' : 'fetchAll'; const method = _.has(request.query, '_q') ? 'search' : 'fetchAll';
const query = pm.queryFrom(request.query); const query = pm.queryFrom(request.query);
const results = await contentManagerService[method](model, query); const { kind } = strapi.getModel(model);
let results;
if (kind === 'singleType') {
// fetchAll for a singleType only return on entity
const results = await contentManagerService.fetchAll(model, query);
if (results && pm.ability.cannot(pm.action, pm.toSubject(results))) {
return ctx.forbidden();
}
}
results = await contentManagerService[method](model, query);
if (!results) { if (!results) {
return ctx.notFound(); return ctx.notFound();

View File

@ -51,7 +51,7 @@ module.exports = {
delete(model, id, query) { delete(model, id, query) {
return strapi.entityService.delete( return strapi.entityService.delete(
{ params: { ...query, _where: _.concat({ id }, query._where) } }, { params: { ...query, _where: _.concat({ id }, query._where || {}) } },
{ model } { model }
); );
}, },
@ -64,7 +64,7 @@ module.exports = {
params: { params: {
_limit: 100, _limit: 100,
...query, ...query,
_where: _.concat({ [`${primaryKey}_in`]: ids }, query._where), _where: _.concat({ [`${primaryKey}_in`]: ids }, query._where || {}),
}, },
}, },
{ model } { model }