From e0fbaa86d930f20f15c63bdfabbf6ddb9c2d13bc Mon Sep 17 00:00:00 2001 From: "kelly.nguyen" <kelly.nguyen@etu.hesge.ch> Date: Wed, 28 Feb 2024 20:21:15 +0100 Subject: [PATCH] add command list and delete for assignment --- .../commander/assignment/AssignmentCommand.ts | 4 ++ .../subcommands/AssignmentDeleteCommand.ts | 48 +++++++++++++++++ .../subcommands/AssignmentListCommand.ts | 54 +++++++++++++++++++ NodeApp/src/managers/DojoBackendManager.ts | 9 +++- 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 NodeApp/src/commander/assignment/subcommands/AssignmentDeleteCommand.ts create mode 100644 NodeApp/src/commander/assignment/subcommands/AssignmentListCommand.ts diff --git a/NodeApp/src/commander/assignment/AssignmentCommand.ts b/NodeApp/src/commander/assignment/AssignmentCommand.ts index b54c2cb..7e9e022 100644 --- a/NodeApp/src/commander/assignment/AssignmentCommand.ts +++ b/NodeApp/src/commander/assignment/AssignmentCommand.ts @@ -5,6 +5,8 @@ import AssignmentUnpublishCommand from './subcommands/AssignmentUnpublishComman import AssignmentCheckCommand from './subcommands/AssignmentCheckCommand'; import AssignmentRunCommand from './subcommands/AssignmentRunCommand'; import AssignmentCorrectionCommand from './subcommands/correction/AssignmentCorrectionCommand'; +import AssignmentDeleteCommand from './subcommands/AssignmentDeleteCommand'; +import AssignmentListCommand from './subcommands/AssignmentListCommand'; class AssignmentCommand extends CommanderCommand { @@ -22,6 +24,8 @@ class AssignmentCommand extends CommanderCommand { AssignmentPublishCommand.registerOnCommand(this.command); AssignmentUnpublishCommand.registerOnCommand(this.command); AssignmentCorrectionCommand.registerOnCommand(this.command); + AssignmentDeleteCommand.registerOnCommand(this.command); + AssignmentListCommand.registerOnCommand(this.command); } protected async commandAction(): Promise<void> { } diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentDeleteCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentDeleteCommand.ts new file mode 100644 index 0000000..12a58ba --- /dev/null +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentDeleteCommand.ts @@ -0,0 +1,48 @@ +import chalk from "chalk"; +import CommanderCommand from "../../CommanderCommand"; +import DojoBackendManager from "../../../managers/DojoBackendManager"; +import ora from "ora"; +import Assignment from "../../../sharedByClients/models/Assignment"; + +class AssignmentDeleteCommand extends CommanderCommand { + protected commandName : string = 'delete'; + + protected defineCommand(): void { + this.command + .description('delete an assignment') + .argument('<assignmentName>', 'name of the assignment') + .option('-v, --verbose', 'verbose mode - display principal container output in live') + .action(this.commandAction.bind(this)); + } + + protected async commandAction(assignmentName : string): Promise<void> { + let assign : Assignment[] = []; + + { + console.log(chalk.cyan('Please wait while we are retrieving the users...')); + assign = await DojoBackendManager.delAssignment(assignmentName); + const oraInfo = (message: string) => { + ora({ + text: message, + indent: 4 + }).start().info(); + }; + console.log(assign) + // assign.forEach(a => { + // oraInfo(`${chalk.magenta('ID :')} ${a.gitlabId}`); + // oraInfo(`${chalk.magenta('Assignment :')} ${a.name}`); + // a.staff.forEach( s => { + // oraInfo(`${chalk.magenta('Info :')} ${s.gitlabLastInfo}`); + // oraInfo(`${chalk.magenta('Staff :')} ${s.gitlabUsername}`); + // }) + // console.log() + // }) + // assign.exercises.forEach( ex => { + // oraInfo(`${chalk.magenta('Exercice :')} ${ex.assignmentName}`); + // }) + } + + } +} + +export default new AssignmentDeleteCommand(); \ No newline at end of file diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentListCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentListCommand.ts new file mode 100644 index 0000000..9867e02 --- /dev/null +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentListCommand.ts @@ -0,0 +1,54 @@ +import chalk from "chalk"; +import CommanderCommand from "../../CommanderCommand"; +import DojoBackendManager from "../../../managers/DojoBackendManager"; +import ora from "ora"; +import User from "../../../sharedByClients/models/User"; +import SessionManager from "../../../managers/SessionManager"; + +class AssignmentListCommand extends CommanderCommand { + protected commandName : string = 'list'; + + protected defineCommand(): void { + this.command + .description('list all the user') + .argument('<userId>', 'id of the user') + .action(this.commandAction.bind(this)); + } + + protected async commandAction(id : string): Promise<void> { + let user : User; + { + console.log(chalk.cyan('Please wait while we are retrieving the assignments...')); + + if ( !await SessionManager.testSession(true, null) ) { + return; + } + + user = await DojoBackendManager.getUserAssignments(id); + if ( !user ) { + return; + } + + const oraInfo = (message: string) => { + ora({ + text: message, + indent: 4 + }).start().info(); + }; + + oraInfo(`${chalk.magenta('Id :')} ${user.id}`); + oraInfo(`${chalk.magenta('Name :')} ${user.gitlabUsername}`); + oraInfo(`${chalk.magenta('Role :')} ${user.role}`); + console.log(); + user.assignments?.forEach(assign => { + const d = new Date(assign.gitlabCreationInfo.last_activity_at).toDateString(); + + oraInfo(`${chalk.magenta(`Assignment ${assign.gitlabId}: `)} ${assign.name}`); + oraInfo(`${chalk.magenta(`Last Activity : `)} ${d}`); + oraInfo(`${chalk.magenta(`Link :`)} ${assign.gitlabLink}`); + }); + } + } +} + +export default new AssignmentListCommand(); \ No newline at end of file diff --git a/NodeApp/src/managers/DojoBackendManager.ts b/NodeApp/src/managers/DojoBackendManager.ts index fcd749d..a8d426e 100644 --- a/NodeApp/src/managers/DojoBackendManager.ts +++ b/NodeApp/src/managers/DojoBackendManager.ts @@ -29,7 +29,6 @@ class DojoBackendManager { } } - public async refreshTokens(refreshToken: string): Promise<GitlabToken> { return (await axios.post<DojoBackendResponse<GitlabToken>>(this.getApiUrl(ApiRoute.REFRESH_TOKENS), { refreshToken: refreshToken @@ -235,6 +234,14 @@ class DojoBackendManager { return false; } } + + public async getUserAssignments(id : string) : Promise<User> { + return (await axios.get<DojoBackendResponse<User>>(this.getApiUrl(ApiRoute.USER_ASSIGNMENTS).replace('{{userId}}', id))).data.data; + } + + public async delAssignment(assignmentName : string) : Promise<Assignment[]> { + return (await axios.get<DojoBackendResponse<Assignment[]>>(this.getApiUrl(ApiRoute.ASSIGNMENT_DEL).replace('{{assignmentNameOrUrl}}', encodeURIComponent(assignmentName)))).data.data; + } } -- GitLab