mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 13:52:38 +08:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
const errors = require('../../errors');
|
|
const UsersService = require('../../services/users');
|
|
|
|
const setUserStatus = ({user}, {id, status}) => {
|
|
return UsersService.setStatus(id, status)
|
|
.then(res => res);
|
|
};
|
|
|
|
const suspendUser = ({user}, {id, message}) => {
|
|
return UsersService.suspendUser(id, message)
|
|
.then(res => {
|
|
return res;
|
|
});
|
|
};
|
|
|
|
const ignoreUser = async ({user}, userToIgnore) => {
|
|
return await UsersService.ignoreUsers(user.id, [userToIgnore.id]);
|
|
};
|
|
|
|
module.exports = (context) => {
|
|
let mutators = {
|
|
User: {
|
|
setUserStatus: () => Promise.reject(errors.ErrNotAuthorized),
|
|
suspendUser: () => Promise.reject(errors.ErrNotAuthorized),
|
|
ignoreUser: (action) => ignoreUser(context, action),
|
|
}
|
|
};
|
|
|
|
if (context.user && context.user.can('mutation:setUserStatus')) {
|
|
mutators.User.setUserStatus = (action) => setUserStatus(context, action);
|
|
}
|
|
|
|
if (context.user && context.user.can('mutation:suspendUser')) {
|
|
mutators.User.suspendUser = (action) => suspendUser(context, action);
|
|
}
|
|
|
|
return mutators;
|
|
};
|