@programisto/edrm-exams 0.2.9 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ const contextBuilder = {
30
30
  const instruction = question.instruction;
31
31
  const maxScore = question.maxScore;
32
32
  const questionType = question.questionType;
33
- const possibleResponses = question.possibleResponses.map((response, index) => `réponse ${index + 1} = ${response}`).join('\n');
33
+ const possibleResponses = question.possibleResponses.map((response, index) => `réponse ${index + 1} = "${response.possibleResponse}" (${response.valid ? 'correcte' : 'incorrecte'})`).join('\n');
34
34
  const context = {
35
35
  instruction,
36
36
  response,
@@ -128,13 +128,15 @@ class ResultRouter extends EnduranceRouter {
128
128
  // Calculer la somme du temps de toutes les questions
129
129
  const questions = await TestQuestion.find({ _id: { $in: (test.questions || []).map((q) => q.questionId) } }).lean();
130
130
  const maxTime = questions.reduce((sum, q) => sum + (q.time || 0), 0);
131
+ const numberOfQuestions = questions.length;
131
132
  // Construire la réponse sans les questions
132
133
  const { questions: _questions, // on retire les questions
133
134
  ...testWithoutQuestions } = test;
134
135
  return res.json({
135
136
  ...testWithoutQuestions,
136
137
  categories: categoriesWithNames,
137
- maxTime
138
+ maxTime,
139
+ numberOfQuestions
138
140
  });
139
141
  }
140
142
  catch (err) {
@@ -227,12 +229,15 @@ class ResultRouter extends EnduranceRouter {
227
229
  return res.status(404).json({ message: 'Question non trouvée' });
228
230
  }
229
231
  // Optionnel : vérifier que la question appartient bien au test de la session et n'a pas déjà été répondue
232
+ let test = null;
233
+ let questionPosition = -1;
234
+ let numberOfQuestions = 0;
230
235
  if (sessionId) {
231
236
  const result = await TestResult.findById(sessionId).lean();
232
237
  if (!result) {
233
238
  return res.status(404).json({ message: 'Session (résultat) non trouvée' });
234
239
  }
235
- const test = await Test.findById(result.testId).lean();
240
+ test = await Test.findById(result.testId).lean();
236
241
  if (!test) {
237
242
  return res.status(404).json({ message: 'Test non trouvé' });
238
243
  }
@@ -246,7 +251,29 @@ class ResultRouter extends EnduranceRouter {
246
251
  return res.status(403).json({ message: 'Question déjà répondue pour cette session' });
247
252
  }
248
253
  }
249
- return res.json({ question });
254
+ else {
255
+ // Si pas de sessionId, on doit quand même récupérer le test pour avoir les infos
256
+ // Chercher dans tous les tests pour trouver celui qui contient cette question
257
+ const allTests = await Test.find({}).lean();
258
+ for (const t of allTests) {
259
+ const questionIds = (t.questions || []).map((q) => q.questionId?.toString());
260
+ if (questionIds.includes(idQuestion)) {
261
+ test = t;
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ // Calculer la position de la question et le nombre total de questions
267
+ if (test) {
268
+ numberOfQuestions = test.questions?.length || 0;
269
+ const questionIndex = test.questions?.findIndex((q) => q.questionId?.toString() === idQuestion);
270
+ questionPosition = questionIndex !== -1 ? questionIndex + 1 : -1; // +1 car les positions commencent à 1
271
+ }
272
+ return res.json({
273
+ question,
274
+ numberOfQuestions,
275
+ questionPosition
276
+ });
250
277
  }
251
278
  catch (err) {
252
279
  console.error('Erreur lors de la récupération de la question :', err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@programisto/edrm-exams",
4
- "version": "0.2.9",
4
+ "version": "0.2.11",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },