2020-05-18 19:54:43 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { validateProfileUpdateInput } = require('../validation/user');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
async getMe(ctx) {
|
|
|
|
const userInfo = strapi.admin.services.user.sanitizeUser(ctx.state.user);
|
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
data: userInfo,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
async updateMe(ctx) {
|
|
|
|
const input = ctx.request.body;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await validateProfileUpdateInput(input);
|
|
|
|
} catch (err) {
|
|
|
|
return ctx.badRequest('ValidationError', err);
|
|
|
|
}
|
|
|
|
|
2020-05-18 20:39:39 +02:00
|
|
|
const updatedUser = await strapi.admin.services.user.update({ id: ctx.state.user.id }, input);
|
2020-05-18 19:54:43 +02:00
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
data: strapi.admin.services.user.sanitizeUser(updatedUser),
|
|
|
|
};
|
|
|
|
},
|
2020-06-11 10:54:26 +02:00
|
|
|
|
|
|
|
async getOwnPermissions(ctx) {
|
|
|
|
const { findUserPermissions, sanitizePermission } = strapi.admin.services.permission;
|
|
|
|
|
|
|
|
const userPermissions = await findUserPermissions(ctx.state.user);
|
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
data: userPermissions.map(sanitizePermission),
|
|
|
|
};
|
|
|
|
},
|
2020-05-18 19:54:43 +02:00
|
|
|
};
|