Skip to content
Snippets Groups Projects
Select Git revision
  • 4ab26cc7d090a884735fe693366377f6f5b8ae75
  • main default protected
  • jw_sonar
  • v6.0.0 protected
  • interactive-mode-preference
  • bedran_exercise-list
  • add_route_user
  • Jw_sonar_backup
  • exercise_list_filter
  • assignment_filter
  • add_route_assignments
  • move-to-esm-only
  • 6.0.0-dev
  • Pre-alpha
  • 5.0.0
  • Latest
  • 4.2.0
  • 4.1.1
  • 4.1.0
  • 4.0.1
  • 4.0.0
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.3.0
  • 3.2.3
  • 3.2.2
  • 3.2.0
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
32 results

UserChangeRoleCommand.ts

Blame
  • 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();