Skip to content
Snippets Groups Projects
Commit 360349a0 authored by PASQUIER-TROIANO AZZO's avatar PASQUIER-TROIANO AZZO
Browse files

feature: bug, i do not get the answer on run/skipAnswers endpoint

parent e1285411
Branches develop
No related merge requests found
Pipeline #325970 passed with stages
in 1 minute and 32 seconds
......@@ -10,6 +10,7 @@ export class AnswerService {
return 'This action adds a new answer';
}
isCorrect(codeQuiz: string, questionID: number, answerID: number) {
return this.answerRepository.isCorrect(codeQuiz, questionID, answerID);
}
......
......@@ -63,6 +63,21 @@ export class RunController {
return { score, answers };
}
@Post('skipAnswer')
async skipAnswer(
@Body() body: { id: string; questionID: number; answerID: number },
) {
const { id } = body;
const response = await this.runService.answers(id);
await this.runService.incrementQuestionIndex(id);
const score = await this.runService.getScore(id);
return { score, response };
}
@Post('question')
async getQuestion(@Body() body: { id: string }) {
try {
......
......@@ -20,35 +20,58 @@ export class RunService {
let gamemodeId: number | undefined;
let difficultyId: number | undefined;
// Utiliser un switch pour mapper les valeurs
switch (mode) {
case 'time_mode':
gamemodeId = 1; // Exemple : time_mode correspond à l'ID 1
break;
case 'classic':
gamemodeId = 2; // Exemple : classic correspond à l'ID 2
break;
default:
throw new Error(`Invalid mode: ${mode}`);
}
// Mapper les IDs pour difficultyId
switch (modeDifficulty) {
case 'easy':
difficultyId = 1; // Exemple : easy correspond à l'ID 1
difficultyId = 1;
break;
case 'medium':
difficultyId = 2; // Exemple : medium correspond à l'ID 2
difficultyId = 2;
break;
case 'hard':
difficultyId = 3; // Exemple : hard correspond à l'ID 3
difficultyId = 3;
break;
default:
throw new Error(`Invalid modeDifficulty: ${modeDifficulty}`);
}
// Vérifier que les IDs ont été correctement définis
// Mapper les IDs pour gamemodeId en fonction de mode et difficultyId
switch (mode) {
case 'time_mode':
switch (difficultyId) {
case 1:
gamemodeId = 1; // time_mode + easy
break;
case 2:
gamemodeId = 3; // time_mode + medium
break;
case 3:
gamemodeId = 2; // time_mode + hard
break;
}
break;
case 'classic':
switch (difficultyId) {
case 1:
gamemodeId = 4; // classic + easy
break;
case 2:
gamemodeId = 6; // classic + medium
break;
case 3:
gamemodeId = 5; // classic + hard
break;
}
break;
default:
throw new Error(`Invalid mode: ${mode}`);
}
// Vérification finale des IDs
if (!gamemodeId || !difficultyId) {
throw new Error('Invalid mode or modeDifficulty');
throw new Error('Gamemode ID or Difficulty ID could not be determined');
}
// Appeler la méthode du repository avec les IDs correspondants
......@@ -253,4 +276,8 @@ export class RunService {
// Retourne le temps associé à la difficulté ou une valeur par défaut si non trouvée
return timeMapping[difficulty] ?? 0;
}
async answers(id: string) {
return this.runRepository.answers(id);
}
}
......@@ -356,4 +356,39 @@ export class RunRepositoryOnDb implements RunRepository {
},
});
}
async answers(id: string): Promise<any> {
// Récupérer la Run avec les AnswerRuns associés, ainsi que les Questions et leurs Answers
const runWithAnswers = await this.prisma.run.findUnique({
where: {
id,
},
include: {
answerRuns: {
include: {
question: {
include: {
answers: true, // Inclure toutes les réponses de chaque question
},
},
},
},
},
});
if (!runWithAnswers) {
throw new Error(`Run with ID ${id} not found`);
}
// Transformer les données pour simplifier la structure si nécessaire
const questionsWithAnswers = runWithAnswers.answerRuns.map((answerRun) => ({
questionId: answerRun.question.id,
questionText: answerRun.question.text,
answers: answerRun.question.answers,
selectedAnswer: answerRun.answerId, // ID de la réponse sélectionnée
}));
return questionsWithAnswers;
}
}
......@@ -34,4 +34,5 @@ export abstract class RunRepository {
abstract info(id: string): Promise<Run | null>;
abstract findLastAnswered(runId: string): Promise<number>;
abstract getGamemode(gamemodeId: number): Promise<any>;
abstract answers(id: string): Promise<any>;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment