added username edit, tests

This commit is contained in:
Wyatt Johnson
2017-11-02 17:54:56 -06:00
parent 04e6f5b52d
commit b5bcbc4fc8
3 changed files with 138 additions and 73 deletions
+1 -18
View File
@@ -8,24 +8,7 @@ const {
} = require('../../perms/constants');
const setUserUsernameStatus = async (ctx, id, status) => {
const user = await UserModel.findOneAndUpdate({id}, {
$set: {
'status.username.status': status
},
$push: {
'status.username.history': {
status,
assigned_by: ctx.user.id,
created_at: Date.now()
}
}
}, {
new: true
});
if (user === null) {
throw errors.ErrNotFound;
}
const user = await UsersService.setUsernameStatus(id, status, ctx.user.id);
if (status === 'REJECTED') {
ctx.pubsub.publish('usernameRejected', user);
}