'use strict'; const { validateRoleUpdateInput } = require('../validation/role'); module.exports = { async findOne(ctx) { const { id } = ctx.params; const role = await strapi.admin.services.role.findOneWithUsersCount({ id }); if (!role) { return ctx.notFound('role.notFound'); } ctx.body = { data: role, }; }, async findAll(ctx) { const roles = await strapi.admin.services.role.findAllWithUsersCount(); 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, }; }, };