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

Exercise[Result|Summary]Command => Disable commands (not working)

parent e8b09ae3
No related branches found
No related tags found
No related merge requests found
Pipeline #38756 passed
...@@ -5,7 +5,6 @@ import ExerciseCorrectionCommand from './subcommands/ExerciseCorrectionCommand.j ...@@ -5,7 +5,6 @@ import ExerciseCorrectionCommand from './subcommands/ExerciseCorrectionCommand.j
import ExerciseDeleteCommand from './subcommands/ExerciseDeleteCommand'; import ExerciseDeleteCommand from './subcommands/ExerciseDeleteCommand';
import ExerciseSearchCommand from './subcommands/ExerciseSearchCommand'; import ExerciseSearchCommand from './subcommands/ExerciseSearchCommand';
import ExerciseInfoCommand from './subcommands/ExerciseInfoCommand'; import ExerciseInfoCommand from './subcommands/ExerciseInfoCommand';
import ExerciseSummaryCommand from "./subcommands/ExerciseSummaryCommand";
class ExerciseCommand extends CommanderCommand { class ExerciseCommand extends CommanderCommand {
...@@ -21,10 +20,10 @@ class ExerciseCommand extends CommanderCommand { ...@@ -21,10 +20,10 @@ class ExerciseCommand extends CommanderCommand {
ExerciseRunCommand.registerOnCommand(this.command); ExerciseRunCommand.registerOnCommand(this.command);
ExerciseDeleteCommand.registerOnCommand(this.command); ExerciseDeleteCommand.registerOnCommand(this.command);
ExerciseCorrectionCommand.registerOnCommand(this.command); ExerciseCorrectionCommand.registerOnCommand(this.command);
ExerciseListCommand.registerOnCommand(this.command); ExerciseSearchCommand.registerOnCommand(this.command);
ExerciseInfoCommand.registerOnCommand(this.command); ExerciseInfoCommand.registerOnCommand(this.command);
ExerciseSummaryCommand.registerOnCommand(this.command); // ExerciseResultCommand.registerOnCommand(this.command);
// ExerciseSummaryCommand.registerOnCommand(this.command);
} }
protected async commandAction(): Promise<void> { protected async commandAction(): Promise<void> {
......
...@@ -6,6 +6,8 @@ import Result from '../../../sharedByClients/models/Result'; ...@@ -6,6 +6,8 @@ import Result from '../../../sharedByClients/models/Result';
import inquirer from 'inquirer'; import inquirer from 'inquirer';
// THIS COMMAND IS NOT WORKING YET - NEEDS TO BE REWRITTEN
class ExerciseResultCommand extends CommanderCommand { class ExerciseResultCommand extends CommanderCommand {
protected commandName: string = 'result'; protected commandName: string = 'result';
...@@ -34,18 +36,16 @@ class ExerciseResultCommand extends CommanderCommand { ...@@ -34,18 +36,16 @@ class ExerciseResultCommand extends CommanderCommand {
if ( results.length === 0 ) { if ( results.length === 0 ) {
spinner.info('No results found for this exercise.'); spinner.info('No results found for this exercise.');
} else { } else {
const answer = await inquirer.prompt([ const answer = await inquirer.prompt([ {
{
type : 'list', type : 'list',
name : 'testType', name : 'testType',
message: 'Choisissez le type de tests à afficher:', message: 'Choisissez le type de tests à afficher:',
choices: ['Tests réussis', 'Tests échoués', 'Les deux'], choices: [ 'Tests réussis', 'Tests échoués', 'Les deux' ]
} } ]);
]);
const { testType } = answer; const { testType } = answer;
this.displayResults(results, testType); this.displayResults(results, testType as string);
spinner.succeed('Exercise results fetched successfully.'); spinner.succeed('Exercise results fetched successfully.');
} }
} catch ( error ) { } catch ( error ) {
...@@ -119,4 +119,6 @@ class ExerciseResultCommand extends CommanderCommand { ...@@ -119,4 +119,6 @@ class ExerciseResultCommand extends CommanderCommand {
}); });
} }
} }
export default new ExerciseResultCommand(); export default new ExerciseResultCommand();
import CommanderCommand from '../../CommanderCommand'; import CommanderCommand from '../../CommanderCommand';
import ora from 'ora'; import ora from 'ora';
import DojoBackendManager from '../../../managers/DojoBackendManager'; import DojoBackendManager from '../../../managers/DojoBackendManager';
import Exercise from "../../../sharedByClients/models/Exercise"; import Exercise from '../../../sharedByClients/models/Exercise';
import Result from '../../../sharedByClients/models/Result'; import Result from '../../../sharedByClients/models/Result';
import Table from 'cli-table3'; import Table from 'cli-table3';
// THIS COMMAND IS NOT WORKING - NEEDS TO BE REWRITTEN AND THINK OF HIS INTEREST
class ExerciseSummaryCommand extends CommanderCommand { class ExerciseSummaryCommand extends CommanderCommand {
protected commandName: string = 'summary'; protected commandName: string = 'summary';
...@@ -41,15 +44,18 @@ class ExerciseSummaryCommand extends CommanderCommand { ...@@ -41,15 +44,18 @@ class ExerciseSummaryCommand extends CommanderCommand {
private async fetchExerciseResults(exercises: Exercise[] | undefined): Promise<{ exercise: Exercise; successfulTests: number; dateTime: string }[]> { private async fetchExerciseResults(exercises: Exercise[] | undefined): Promise<{ exercise: Exercise; successfulTests: number; dateTime: string }[]> {
const results: { exercise: Exercise, successfulTests: number, dateTime: string }[] = []; const results: { exercise: Exercise, successfulTests: number, dateTime: string }[] = [];
// @ts-ignore for ( const exercise of exercises ?? [] ) {
for (const exercise of exercises) {
try { try {
const exerciseId = exercise.id; const exerciseId = exercise.id;
const exerciseResults = await DojoBackendManager.getExerciseResults(exerciseId); const exerciseResults = await DojoBackendManager.getExerciseResults(exerciseId);
if ( exerciseResults ) { if ( exerciseResults ) {
const successfulTests = this.countSuccessfulTests(exerciseResults); const successfulTests = this.countSuccessfulTests(exerciseResults);
results.push({ exercise, successfulTests, dateTime: exerciseResults[0]?.dateTime || '' }); results.push({
exercise,
successfulTests,
dateTime: exerciseResults[0]?.dateTime || ''
});
} }
} catch ( error ) { } catch ( error ) {
console.error(`Error fetching results for exercise ${ exercise.id }:`, error); console.error(`Error fetching results for exercise ${ exercise.id }:`, error);
...@@ -60,7 +66,7 @@ class ExerciseSummaryCommand extends CommanderCommand { ...@@ -60,7 +66,7 @@ class ExerciseSummaryCommand extends CommanderCommand {
} }
private countSuccessfulTests(results: Result[]): number { private countSuccessfulTests(results: Result[]): number {
return results.reduce((count, result) => count + (result.success ? result.results.successfulTestsList.length : 0), 0); return results.reduce((count, result) => count + (result.success ? (result.results.successfulTestsList ?? []).length : 0), 0);
} }
private sortExercisesBySuccessfulTests(exerciseResults: { exercise: Exercise, successfulTests: number, dateTime: string }[]): { exercise: Exercise, successfulTests: number, dateTime: string }[] { private sortExercisesBySuccessfulTests(exerciseResults: { exercise: Exercise, successfulTests: number, dateTime: string }[]): { exercise: Exercise, successfulTests: number, dateTime: string }[] {
...@@ -80,24 +86,21 @@ class ExerciseSummaryCommand extends CommanderCommand { ...@@ -80,24 +86,21 @@ class ExerciseSummaryCommand extends CommanderCommand {
}); });
// Define colWidths based on maxWidths // Define colWidths based on maxWidths
const colWidths = maxWidths.map(width => ({ width })); // const colWidths = maxWidths.map(width => ({ width }));
// Create the table // Create the table
const table = new Table({ const table = new Table({
head: headers, head: headers
}); });
// Populate the table with data // Populate the table with data
sortedExercises.forEach((exercise, index) => { sortedExercises.forEach((exercise, index) => {
table.push([ table.push([ index + 1, exercise.exercise.name, exercise.successfulTests, exercise.dateTime ]);
index + 1,
exercise.exercise.name,
exercise.successfulTests,
exercise.dateTime
]);
}); });
console.log(table.toString(), '\n'); console.log(table.toString(), '\n');
} }
} }
export default new ExerciseSummaryCommand(); export default new ExerciseSummaryCommand();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment