mirror of
https://github.com/strapi/strapi.git
synced 2025-07-19 07:02:26 +00:00
46 lines
963 B
JavaScript
46 lines
963 B
JavaScript
'use strict';
|
|
|
|
const { validateRoleUpdateInput } = require('../validation/role');
|
|
|
|
module.exports = {
|
|
async findOne(ctx) {
|
|
const { id } = ctx.params;
|
|
const role = await strapi.admin.services.role.findOne({ id }, []);
|
|
|
|
if (!role) {
|
|
return ctx.notFound('role.notFound');
|
|
}
|
|
|
|
ctx.body = {
|
|
data: role,
|
|
};
|
|
},
|
|
async findAll(ctx) {
|
|
const roles = await strapi.admin.services.role.findAll([]);
|
|
ctx.body = {
|
|
data: roles,
|
|
};
|
|
},
|
|
async update(ctx) {
|
|
const { id } = ctx.params;
|
|
|
|
try {
|
|
await validateRoleUpdateInput(ctx.request.body);
|
|
} catch (err) {
|
|
return ctx.badRequest('ValidationError', err);
|
|
}
|
|
|
|
const role = await strapi.admin.services.role.update({ id }, ctx.request.body);
|
|
|
|
if (!role) {
|
|
return ctx.notFound('role.notFound');
|
|
}
|
|
|
|
const sanitizedRole = strapi.admin.services.role.sanitizeRole(role);
|
|
|
|
ctx.body = {
|
|
data: sanitizedRole,
|
|
};
|
|
},
|
|
};
|