Select Git revision
UserChangeRoleCommand.ts
UserChangeRoleCommand.ts 1.50 KiB
import chalk from "chalk";
import CommanderCommand from "../../CommanderCommand";
import DojoBackendManager from "../../../managers/DojoBackendManager";
import ora from "ora";
import { StatusCodes } from "http-status-codes";
class UserChangeRoleCommand extends CommanderCommand {
protected commandName : string = 'role';
protected defineCommand(): void {
this.command
.description('change the role of an user')
.arguments('<userId> <newRole>', )
.action(this.commandAction.bind(this));
}
protected async commandAction(id: string, newRole : string): Promise<void> {
{
// if ( !await AccessesHelper.checkTeachingStaff() ) {
// return;
// }
console.log(chalk.cyan('Please wait while we are changing the role of the user...'));
// TODO : newRole -> type UserRole
const upd = await DojoBackendManager.updUserRole(id, newRole);
if (!upd) {
return;
}
const oraInfo = (message: string) => {
ora({
text: message,
indent: 4
}).start().info();
};
if (upd.status == StatusCodes.OK) {
oraInfo(`${chalk.green('Modification success')}`);
}
}
}
}
export default new UserChangeRoleCommand();