Skip to content
Snippets Groups Projects
Commit ed7e1c9d authored by michael.minelli's avatar michael.minelli
Browse files

Commands => Add correction link and update commands

parent 2a48a113
No related branches found
No related tags found
No related merge requests found
Pipeline #29569 passed
import CommanderCommand from '../CommanderCommand'; import CommanderCommand from '../CommanderCommand';
import AssignmentCreateCommand from './subcommands/AssignmentCreateCommand'; import AssignmentCreateCommand from './subcommands/AssignmentCreateCommand';
import AssignmentPublishCommand from './subcommands/AssignmentPublishCommand'; import AssignmentPublishCommand from './subcommands/AssignmentPublishCommand';
import AssignmentUnpublishCommand from './subcommands/AssignmentUnpublishCommand'; import AssignmentUnpublishCommand from './subcommands/AssignmentUnpublishCommand';
import AssignmentCheckCommand from './subcommands/AssignmentCheckCommand'; import AssignmentCheckCommand from './subcommands/AssignmentCheckCommand';
import AssignmentRunCommand from './subcommands/AssignmentRunCommand'; import AssignmentRunCommand from './subcommands/AssignmentRunCommand';
import AssignmentCorrectionCommand from './subcommands/correction/AssignmentCorrectionCommand';
class AssignmentCommand extends CommanderCommand { class AssignmentCommand extends CommanderCommand {
...@@ -20,6 +21,7 @@ class AssignmentCommand extends CommanderCommand { ...@@ -20,6 +21,7 @@ class AssignmentCommand extends CommanderCommand {
AssignmentRunCommand.registerOnCommand(this.command); AssignmentRunCommand.registerOnCommand(this.command);
AssignmentPublishCommand.registerOnCommand(this.command); AssignmentPublishCommand.registerOnCommand(this.command);
AssignmentUnpublishCommand.registerOnCommand(this.command); AssignmentUnpublishCommand.registerOnCommand(this.command);
AssignmentCorrectionCommand.registerOnCommand(this.command);
} }
protected async commandAction(): Promise<void> { } protected async commandAction(): Promise<void> { }
......
import CommanderCommand from '../../../CommanderCommand';
import AssignmentCorrectionLinkCommand from './subcommands/AssignmentCorrectionLinkCommand';
import AssignmentCorrectionUpdateCommand from './subcommands/AssignmentCorrectionUpdateCommand';
class AssignmentCorrectionCommand extends CommanderCommand {
protected commandName: string = 'correction';
protected defineCommand() {
this.command
.description('manage corrections of an assignment');
}
protected defineSubCommands() {
AssignmentCorrectionLinkCommand.registerOnCommand(this.command);
AssignmentCorrectionUpdateCommand.registerOnCommand(this.command);
}
protected async commandAction(): Promise<void> { }
}
export default new AssignmentCorrectionCommand();
\ No newline at end of file
import AssignmentCorrectionLinkUpdateCommand from './AssignmentCorrectionLinkUpdateCommand';
class AssignmentCorrectionLinkCommand extends AssignmentCorrectionLinkUpdateCommand {
protected commandName: string = 'link';
protected isUpdate: boolean = false;
}
export default new AssignmentCorrectionLinkCommand();
\ No newline at end of file
import CommanderCommand from '../../../../CommanderCommand';
import chalk from 'chalk';
import ora from 'ora';
import DojoBackendManager from '../../../../../managers/DojoBackendManager';
import SessionManager from '../../../../../managers/SessionManager';
import Assignment from '../../../../../sharedByClients/models/Assignment';
abstract class AssignmentCorrectionLinkUpdateCommand extends CommanderCommand {
protected abstract isUpdate: boolean;
protected defineCommand() {
this.command
.description(this.isUpdate ? 'update a correction of an assignment' : 'link an exercise repo as a correction for an assignment')
.argument('<string>', 'id or url of the exercise that is the correction')
.requiredOption('-a, --assignment <string>', 'id or url of the assignment of the correction')
.action(this.commandAction.bind(this));
}
protected async commandAction(exerciseIdOrUrl: string, options: { assignment: string }): Promise<void> {
let assignment!: Assignment | undefined;
// Check access
{
console.log(chalk.cyan('Please wait while we check access...'));
const assignmentGetSpinner: ora.Ora = ora('Checking if assignment exists').start();
assignment = await DojoBackendManager.getAssignment(options.assignment);
if ( !assignment ) {
assignmentGetSpinner.fail(`The assignment doesn't exists`);
return;
}
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;
}
assignmentAccessSpinner.succeed(`You are in the staff of the assignment`);
const assignmentPublishedSpinner: ora.Ora = ora('Checking assignment').start();
if ( !assignment.published ) {
assignmentPublishedSpinner.fail(`Assignment is not published`);
return;
}
assignmentPublishedSpinner.succeed(`Assignment is published`);
}
// Link the exercise
{
console.log(chalk.cyan('Please wait while we link the exercise...'));
await DojoBackendManager.linkUpdateCorrection(exerciseIdOrUrl, assignment, this.isUpdate);
}
}
}
export default AssignmentCorrectionLinkUpdateCommand;
\ No newline at end of file
import AssignmentCorrectionLinkUpdateCommand from './AssignmentCorrectionLinkUpdateCommand';
class AssignmentCorrectionUpdateCommand extends AssignmentCorrectionLinkUpdateCommand {
protected commandName: string = 'update';
protected isUpdate: boolean = true;
}
export default new AssignmentCorrectionUpdateCommand();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment