Skip to content
Snippets Groups Projects
Select Git revision
  • f4ed114bbd21f1ca202b0a5030f5edc7672bce5c
  • 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

GlobalHelper.ts

Blame
  • GlobalHelper.ts 2.23 KiB
    import { Command, Option } from 'commander';
    import SessionManager      from '../managers/SessionManager.js';
    import TextStyle           from '../types/TextStyle.js';
    import ora                 from 'ora';
    import DojoBackendManager  from '../managers/DojoBackendManager.js';
    import Assignment          from '../sharedByClients/models/Assignment.js';
    import Config              from '../config/Config';
    
    
    class GlobalHelper {
        public runCommandDefinition(command: Command, isAssignment: boolean = true): Command {
            command
                .option('-p, --path <value>', `${ isAssignment ? 'assignment' : 'exercise' } path`, Config.folders.defaultLocalExercise)
                .option('-v, --verbose', 'verbose mode - display principal container output in live')
                .addOption(new Option('-w, --super-verbose', 'verbose mode - display all docker compose logs (build included) in live').conflicts('verbose'))
                .addOption(new Option('--verbose-ssj2').hideHelp().implies({ superVerbose: true }));
    
            return command;
        }
    
    
        public readonly refreshGitlabTokenFunction = async () => {
            await SessionManager.refreshTokens();
    
            return SessionManager.gitlabCredentials.accessToken ?? '';
        };
    
    
        public async checkAssignmentCorrectionAccess(assignmentName: string): Promise<Assignment | undefined> {
            console.log(TextStyle.BLOCK('Please wait while we check access...'));
    
            const assignmentGetSpinner: ora.Ora = ora('Checking if assignment exists').start();
            const assignment = await DojoBackendManager.getAssignment(assignmentName);
            if ( !assignment ) {
                assignmentGetSpinner.fail(`The assignment doesn't exists`);
                return undefined;
            }
            assignmentGetSpinner.succeed(`The assignment exists`);
    
    
            const assignmentAccessSpinner: ora.Ora = ora('Checking assignment access').start();
            if ( assignment.staff.find(staff => staff.id === SessionManager.profile?.id) === undefined ) {
                assignmentAccessSpinner.fail(`You are not in the staff of the assignment`);
                return undefined;
            }
            assignmentAccessSpinner.succeed(`You are in the staff of the assignment`);
    
            return assignment;
        }
    }
    
    
    export default new GlobalHelper();