diff --git a/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts b/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts index d2c326b386b3debd9cd1bf33515e8fca85b80291..aaceb52b2020c209c7a645f11a97889e002cf484 100644 --- a/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts +++ b/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts @@ -9,7 +9,7 @@ import TextStyle from "../../../types/TextStyle"; import GitlabManager from "../../../managers/GitlabManager"; import User from "../../../sharedByClients/models/User"; -// type CommandOptions = { name: string } +type CommandOptions = { id : string, nameFile : string, full : boolean } // type CommandOptions = { name: string, template?: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean } class UserCreateResumeCommand extends CommanderCommand { @@ -18,14 +18,14 @@ class UserCreateResumeCommand extends CommanderCommand { protected defineCommand(): void { this.command .description('export the portfolio of an user') - .argument('<userId>', 'id of the user') - .argument('<pathFile>', 'path of the file') - // .option('-n, --name <name>', 'name of the assignment') + .requiredOption('-u, --id <id>', 'id of the user') + .requiredOption('-n, --nameFile <string>', 'path of the file') + .option('--full', 'full export') .action(this.commandAction.bind(this)); // .action((options) => this.commandAction(options)); } // protected async commandAction(options: { name: string }): Promise<void> { - protected async commandAction(userId : string, pathFile : string): Promise<void> { + protected async commandAction(options : CommandOptions): Promise<void> { // check privileges console.log(chalk.cyan('Please wait while we are exporting the resume...')); @@ -42,7 +42,7 @@ class UserCreateResumeCommand extends CommanderCommand { }).start(); try { - const resumeCreated = await DojoBackendManager.createResumeUser(userId); + const resumeCreated = await DojoBackendManager.createResumeUser(options.id); if (!resumeCreated) { resumeSpinner.fail('Failed to create resume'); @@ -50,47 +50,49 @@ class UserCreateResumeCommand extends CommanderCommand { } // START LIGHT EXPORT - // const portfolioCreated = await DojoBackendManager.createPortfolio(userId); - - // if (!portfolioCreated) { - // resumeSpinner.fail('Failed to create portfolio'); - // return; - // } - - // await this.sleep(2000); - // END LIGHT EXPORT - - // START COMPLET EXPORT - const userDataAssignment : User = await DojoBackendManager.getUserAssignments(userId); - const userDataExercise : User = await DojoBackendManager.getUserExercises(userId); - - if (!userDataAssignment) { - resumeSpinner.fail('Failed to create portfolio'); - return; - } - if (!userDataExercise) { - resumeSpinner.fail('Failed to create portfolio'); - return; + if (!options.full) { + const portfolioCreated = await DojoBackendManager.createPortfolio(options.id); + + if (!portfolioCreated) { + resumeSpinner.fail('Failed to create portfolio'); + return; + } + + await this.sleep(2000); + // END LIGHT EXPORT + } else { + // START COMPLET EXPORT + const userDataAssignment : User = await DojoBackendManager.getUserAssignments(options.id); + const userDataExercise : User = await DojoBackendManager.getUserExercises(options.id); + + if (!userDataAssignment) { + resumeSpinner.fail('Failed to create portfolio'); + return; + } + if (!userDataExercise) { + resumeSpinner.fail('Failed to create portfolio'); + return; + } + const pathAssignments = userDataAssignment.gitlabUsername + '/assignments' + const pathExercises = userDataAssignment.gitlabUsername + '/exercises' + + userDataAssignment.assignments?.forEach(el => { + this.cloneRepository(pathAssignments, el.gitlabCreationInfo.ssh_url_to_repo, el.name); + }); + + userDataExercise.exercises?.forEach(el => { + this.cloneRepository(pathExercises, el.gitlabCreationInfo.ssh_url_to_repo, el.name); + }); + + // END COMPLET EXPORT + await this.sleep(2000); } - const pathAssignments = userDataAssignment.gitlabUsername + '/assignments' - const pathExercises = userDataAssignment.gitlabUsername + '/exercises' - - userDataAssignment.assignments?.forEach(el => { - this.cloneRepository(pathAssignments, el.gitlabCreationInfo.ssh_url_to_repo, el.name); - }); - - userDataExercise.exercises?.forEach(el => { - this.cloneRepository(pathExercises, el.gitlabCreationInfo.ssh_url_to_repo, el.name); - }); - - // END COMPLET EXPORT - resumeSpinner.succeed('File downloaded and saved successfully.'); - // this.downloadFile(userId, pathFile).then(() => { - // resumeSpinner.succeed('File downloaded and saved successfully.'); - // }).catch((error) => { - // resumeSpinner.fail(`Error download : ${error}`); - // }); + this.downloadFile(options).then(() => { + resumeSpinner.succeed('File downloaded and saved successfully.'); + }).catch((error) => { + resumeSpinner.fail(`Error download : ${error}`); + }); } catch (error) { @@ -103,11 +105,12 @@ class UserCreateResumeCommand extends CommanderCommand { return new Promise(resolve => setTimeout(resolve, ms)); } - private async downloadFile(id : string, pathFile : string) { + private async downloadFile(options : CommandOptions) { try { - const response = await DojoBackendManager.createZip(id); + const response = await DojoBackendManager.createZip(options.id); - const filePath = path.join(__dirname, pathFile); + // const filePath = path.join(options.pathFile); + const filePath = path.join(__dirname, options.nameFile); const writer = fs.createWriteStream(filePath); response.data.pipe(writer);