diff --git a/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts b/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts index aaceb52b2020c209c7a645f11a97889e002cf484..9cf6e49c85ba28c756050ab09d6efbf1abc24819 100644 --- a/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts +++ b/NodeApp/src/commander/user/subcommands/UserCreateResumeCommand.ts @@ -8,9 +8,9 @@ import path from 'path'; import TextStyle from "../../../types/TextStyle"; import GitlabManager from "../../../managers/GitlabManager"; import User from "../../../sharedByClients/models/User"; +import test from "node:test"; -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 } +type CommandOptions = { id : string, nameFile : string, full : boolean, test : boolean} class UserCreateResumeCommand extends CommanderCommand { protected commandName : string = 'resume'; @@ -21,8 +21,8 @@ class UserCreateResumeCommand extends CommanderCommand { .requiredOption('-u, --id <id>', 'id of the user') .requiredOption('-n, --nameFile <string>', 'path of the file') .option('--full', 'full export') + .option('--test', 'test command') .action(this.commandAction.bind(this)); - // .action((options) => this.commandAction(options)); } // protected async commandAction(options: { name: string }): Promise<void> { protected async commandAction(options : CommandOptions): Promise<void> { @@ -42,59 +42,63 @@ class UserCreateResumeCommand extends CommanderCommand { }).start(); try { - const resumeCreated = await DojoBackendManager.createResumeUser(options.id); - - if (!resumeCreated) { - resumeSpinner.fail('Failed to create resume'); - return; - } - - // START LIGHT EXPORT - 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 + if (options.test) { + const res = await DojoBackendManager.createStaticPage(options.id); + console.log(res); } 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'); + const resumeCreated = await DojoBackendManager.createResumeUser(options.id); + + if (!resumeCreated) { + resumeSpinner.fail('Failed to create resume'); 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); - }); + // START LIGHT EXPORT + 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); + } - userDataExercise.exercises?.forEach(el => { - this.cloneRepository(pathExercises, el.gitlabCreationInfo.ssh_url_to_repo, el.name); + this.downloadFile(options).then(() => { + resumeSpinner.succeed('File downloaded and saved successfully.'); + }).catch((error) => { + resumeSpinner.fail(`Error download : ${error}`); }); - - // END COMPLET EXPORT - await this.sleep(2000); } - this.downloadFile(options).then(() => { - resumeSpinner.succeed('File downloaded and saved successfully.'); - }).catch((error) => { - resumeSpinner.fail(`Error download : ${error}`); - }); - - } catch (error) { console.log(error); resumeSpinner.fail('Error during export process'); diff --git a/NodeApp/src/commander/user/subcommands/working.zip b/NodeApp/src/commander/user/subcommands/working.zip new file mode 100644 index 0000000000000000000000000000000000000000..aa807c61213a2f72e56c9a97b663acd0d26570f4 Binary files /dev/null and b/NodeApp/src/commander/user/subcommands/working.zip differ diff --git a/NodeApp/src/managers/DojoBackendManager.ts b/NodeApp/src/managers/DojoBackendManager.ts index 01cc49567cda6dde81aa24183c98354f70c4f5e4..a798a484f87e8120437b87aba8ef37b074d1d892 100644 --- a/NodeApp/src/managers/DojoBackendManager.ts +++ b/NodeApp/src/managers/DojoBackendManager.ts @@ -290,18 +290,7 @@ class DojoBackendManager { }))).data.data); } - public async createZip(userId : string) { - // return ((await axios.get<DojoBackendResponse<null>>(DojoBackendHelper.getApiUrl(ApiRoute.USER_EXPORTZIP, { - // userId : userId, - // }), { - // responseType: 'stream' - // })).data.data); - // return await axios.get(DojoBackendHelper.getApiUrl(ApiRoute.USER_EXPORTZIP, { - // userId: userId - // }), { - // responseType: 'stream' - // }); - + public async createZip(userId : string) { const url = DojoBackendHelper.getApiUrl(ApiRoute.USER_EXPORTZIP, { userId: userId }); @@ -312,6 +301,12 @@ class DojoBackendManager { }); return response; } + + public async createStaticPage(userId : string) { + return ((await axios.get<DojoBackendResponse<null>>(DojoBackendHelper.getApiUrl(ApiRoute.USER_STATICPAGE, { + userId : userId + }))).data.data); + } }