mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 12:27:33 +00:00
Add single type usecase and fix delete
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
44a7e2321d
commit
3ff5f645c8
@ -84,7 +84,19 @@ module.exports = {
|
||||
const method = _.has(request.query, '_q') ? 'search' : 'fetchAll';
|
||||
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) {
|
||||
return ctx.notFound();
|
||||
|
@ -51,7 +51,7 @@ module.exports = {
|
||||
|
||||
delete(model, id, query) {
|
||||
return strapi.entityService.delete(
|
||||
{ params: { ...query, _where: _.concat({ id }, query._where) } },
|
||||
{ params: { ...query, _where: _.concat({ id }, query._where || {}) } },
|
||||
{ model }
|
||||
);
|
||||
},
|
||||
@ -64,7 +64,7 @@ module.exports = {
|
||||
params: {
|
||||
_limit: 100,
|
||||
...query,
|
||||
_where: _.concat({ [`${primaryKey}_in`]: ids }, query._where),
|
||||
_where: _.concat({ [`${primaryKey}_in`]: ids }, query._where || {}),
|
||||
},
|
||||
},
|
||||
{ model }
|
||||
|
Loading…
x
Reference in New Issue
Block a user