Skip to content

Commit

Permalink
feat: update user locale (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 26, 2019
1 parent 6b842f7 commit 54fc58a
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/controller/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class UserController extends BaseController<UserControllerData> implement
},
});
if (isNil(role)) {
return this.reply(ctx, this.translate('role-get.missing', {
return this.reply(ctx, this.translate(ctx, 'role-get.missing', {
name,
}));
} else {
Expand Down Expand Up @@ -114,23 +114,42 @@ export class UserController extends BaseController<UserControllerData> implement
@CheckRBAC()
public async updateUser(cmd: Command, ctx: Context): Promise<void> {
const name = cmd.getHeadOrDefault('name', ctx.name);
const roleNames = cmd.getOrDefault('roles', []);
this.logger.debug({ name, roles: roleNames }, 'updating user');
this.logger.debug({ name }, 'updating user');

const user = await this.userRepository.findOneOrFail({
where: {
name,
},
});
const roles = await this.roleRepository.find({
where: {
name: In(roleNames),
},
});
user.roles = roles;

if (cmd.has('roles')) {
const roleNames = cmd.get('roles');
const roles = await this.roleRepository.find({
where: {
name: In(roleNames),
},
});
user.roles = roles;
}

if (cmd.has('date')) {
user.locale.date = cmd.getHead('date');
}

if (cmd.has('lang')) {
user.locale.lang = cmd.getHead('lang');
}

if (cmd.has('time')) {
user.locale.time = cmd.getHead('time');
}

if (cmd.has('timezone')) {
user.locale.timezone = cmd.getHead('timezone');
}

const updatedUser = await this.userRepository.save(user);
return this.reply(ctx, updatedUser.toString());
return this.reply(ctx, `updated user ${updatedUser.name}`);
}

@Handler(NOUN_USER, CommandVerb.Help)
Expand Down

0 comments on commit 54fc58a

Please sign in to comment.