Skip to content
Snippets Groups Projects
Commit 14953733 authored by kelly.nguyen's avatar kelly.nguyen
Browse files

fix issue with export portfolio and add options to cmd

parent 184385ce
Branches
No related tags found
No related merge requests found
Pipeline #33650 failed
...@@ -9,7 +9,7 @@ import TextStyle from "../../../types/TextStyle"; ...@@ -9,7 +9,7 @@ import TextStyle from "../../../types/TextStyle";
import GitlabManager from "../../../managers/GitlabManager"; import GitlabManager from "../../../managers/GitlabManager";
import User from "../../../sharedByClients/models/User"; 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 } // type CommandOptions = { name: string, template?: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean }
class UserCreateResumeCommand extends CommanderCommand { class UserCreateResumeCommand extends CommanderCommand {
...@@ -18,14 +18,14 @@ class UserCreateResumeCommand extends CommanderCommand { ...@@ -18,14 +18,14 @@ class UserCreateResumeCommand extends CommanderCommand {
protected defineCommand(): void { protected defineCommand(): void {
this.command this.command
.description('export the portfolio of an user') .description('export the portfolio of an user')
.argument('<userId>', 'id of the user') .requiredOption('-u, --id <id>', 'id of the user')
.argument('<pathFile>', 'path of the file') .requiredOption('-n, --nameFile <string>', 'path of the file')
// .option('-n, --name <name>', 'name of the assignment') .option('--full', 'full export')
.action(this.commandAction.bind(this)); .action(this.commandAction.bind(this));
// .action((options) => this.commandAction(options)); // .action((options) => this.commandAction(options));
} }
// protected async commandAction(options: { name: string }): Promise<void> { // 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 // check privileges
console.log(chalk.cyan('Please wait while we are exporting the resume...')); console.log(chalk.cyan('Please wait while we are exporting the resume...'));
...@@ -42,7 +42,7 @@ class UserCreateResumeCommand extends CommanderCommand { ...@@ -42,7 +42,7 @@ class UserCreateResumeCommand extends CommanderCommand {
}).start(); }).start();
try { try {
const resumeCreated = await DojoBackendManager.createResumeUser(userId); const resumeCreated = await DojoBackendManager.createResumeUser(options.id);
if (!resumeCreated) { if (!resumeCreated) {
resumeSpinner.fail('Failed to create resume'); resumeSpinner.fail('Failed to create resume');
...@@ -50,19 +50,20 @@ class UserCreateResumeCommand extends CommanderCommand { ...@@ -50,19 +50,20 @@ class UserCreateResumeCommand extends CommanderCommand {
} }
// START LIGHT EXPORT // START LIGHT EXPORT
// const portfolioCreated = await DojoBackendManager.createPortfolio(userId); if (!options.full) {
const portfolioCreated = await DojoBackendManager.createPortfolio(options.id);
// if (!portfolioCreated) { if (!portfolioCreated) {
// resumeSpinner.fail('Failed to create portfolio'); resumeSpinner.fail('Failed to create portfolio');
// return; return;
// } }
// await this.sleep(2000); await this.sleep(2000);
// END LIGHT EXPORT // END LIGHT EXPORT
} else {
// START COMPLET EXPORT // START COMPLET EXPORT
const userDataAssignment : User = await DojoBackendManager.getUserAssignments(userId); const userDataAssignment : User = await DojoBackendManager.getUserAssignments(options.id);
const userDataExercise : User = await DojoBackendManager.getUserExercises(userId); const userDataExercise : User = await DojoBackendManager.getUserExercises(options.id);
if (!userDataAssignment) { if (!userDataAssignment) {
resumeSpinner.fail('Failed to create portfolio'); resumeSpinner.fail('Failed to create portfolio');
...@@ -84,13 +85,14 @@ class UserCreateResumeCommand extends CommanderCommand { ...@@ -84,13 +85,14 @@ class UserCreateResumeCommand extends CommanderCommand {
}); });
// END COMPLET EXPORT // END COMPLET EXPORT
resumeSpinner.succeed('File downloaded and saved successfully.'); await this.sleep(2000);
}
// this.downloadFile(userId, pathFile).then(() => { this.downloadFile(options).then(() => {
// resumeSpinner.succeed('File downloaded and saved successfully.'); resumeSpinner.succeed('File downloaded and saved successfully.');
// }).catch((error) => { }).catch((error) => {
// resumeSpinner.fail(`Error download : ${error}`); resumeSpinner.fail(`Error download : ${error}`);
// }); });
} catch (error) { } catch (error) {
...@@ -103,11 +105,12 @@ class UserCreateResumeCommand extends CommanderCommand { ...@@ -103,11 +105,12 @@ class UserCreateResumeCommand extends CommanderCommand {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
private async downloadFile(id : string, pathFile : string) { private async downloadFile(options : CommandOptions) {
try { 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); const writer = fs.createWriteStream(filePath);
response.data.pipe(writer); response.data.pipe(writer);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment