@programisto/edrm-exams 0.3.5 → 0.3.7

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.
@@ -5,6 +5,25 @@ import TestResult, { TestState } from '../models/test-result.model.js';
5
5
  import CandidateModel from '../models/candidate.model.js';
6
6
  import ContactModel from '../models/contact.model.js';
7
7
  import TestModel from '../models/test.model.js';
8
+ async function sendDiscordNotification(message) {
9
+ const discordWebhook = process.env.TEST_CORRECTION_DISCORD_WEBHOOKS;
10
+ if (discordWebhook) {
11
+ try {
12
+ await fetch(discordWebhook, {
13
+ method: 'POST',
14
+ headers: {
15
+ 'Content-Type': 'application/json'
16
+ },
17
+ body: JSON.stringify({
18
+ content: message
19
+ })
20
+ });
21
+ }
22
+ catch (error) {
23
+ console.error('Error sending Discord notification:', error);
24
+ }
25
+ }
26
+ }
8
27
  async function correctTest(options) {
9
28
  if (!options.testId)
10
29
  throw new Error('TestId is required');
@@ -116,6 +135,13 @@ async function correctTest(options) {
116
135
  testLink
117
136
  }
118
137
  });
138
+ // Envoyer une notification Discord
139
+ const discordMessage = '📊 **Nouveau résultat de test**\n' +
140
+ `**Candidat:** ${contact.firstname} ${contact.lastname}\n` +
141
+ `**Test:** ${test?.title || 'Test inconnu'}\n` +
142
+ `**Score:** ${scorePercentage}%\n` +
143
+ `**Score brut:** ${finalscore}/${maxScore}`;
144
+ await sendDiscordNotification(discordMessage);
119
145
  }
120
146
  }
121
147
  }
@@ -35,7 +35,7 @@ class ExamsRouter extends EnduranceRouter {
35
35
  constructor() {
36
36
  super(EnduranceAuthMiddleware.getInstance());
37
37
  }
38
- async generateAndSaveQuestion(test, categoryInfo, useAssistant = false) {
38
+ async generateAndSaveQuestion(test, categoryInfo, useAssistant = false, questionTypeOverride) {
39
39
  try {
40
40
  const categoryDoc = await TestCategory.findById(categoryInfo.categoryId);
41
41
  if (!categoryDoc) {
@@ -50,7 +50,9 @@ class ExamsRouter extends EnduranceRouter {
50
50
  job: jobName,
51
51
  seniority: test.seniorityLevel,
52
52
  category: categoryDoc.name,
53
- questionType: ['MCQ', 'free question', 'exercice'][Math.floor(Math.random() * 3)],
53
+ questionType: (questionTypeOverride && questionTypeOverride !== 'ALL')
54
+ ? questionTypeOverride
55
+ : ['MCQ', 'free question', 'exercice'][Math.floor(Math.random() * 3)],
54
56
  expertiseLevel: categoryInfo.expertiseLevel,
55
57
  otherQuestions: otherQuestions.map(question => question.instruction).join('\n')
56
58
  };
@@ -990,7 +992,7 @@ class ExamsRouter extends EnduranceRouter {
990
992
  // Générer plusieurs questions pour un test
991
993
  this.put('/test/generateQuestions/:id', authenticatedOptions, async (req, res) => {
992
994
  const { id } = req.params;
993
- const { numberOfQuestions, category } = req.body;
995
+ const { numberOfQuestions, category, questionType } = req.body;
994
996
  if (!numberOfQuestions || numberOfQuestions <= 0) {
995
997
  return res.status(400).json({ message: 'Le nombre de questions doit être positif' });
996
998
  }
@@ -1028,7 +1030,7 @@ class ExamsRouter extends EnduranceRouter {
1028
1030
  const categoryInfo = categoriesToUse[0];
1029
1031
  while (questionsGenerated < numberOfQuestions && attempts < maxAttempts) {
1030
1032
  attempts++;
1031
- const question = await this.generateAndSaveQuestion(test, categoryInfo, true);
1033
+ const question = await this.generateAndSaveQuestion(test, categoryInfo, true, questionType);
1032
1034
  if (question) {
1033
1035
  generatedQuestions.push(question);
1034
1036
  questionsGenerated++;
@@ -1043,7 +1045,7 @@ class ExamsRouter extends EnduranceRouter {
1043
1045
  // Sélectionner une catégorie aléatoire
1044
1046
  const randomCategoryIndex = Math.floor(Math.random() * shuffledCategories.length);
1045
1047
  const categoryInfo = shuffledCategories[randomCategoryIndex];
1046
- const question = await this.generateAndSaveQuestion(test, categoryInfo, true);
1048
+ const question = await this.generateAndSaveQuestion(test, categoryInfo, true, questionType);
1047
1049
  if (question) {
1048
1050
  generatedQuestions.push(question);
1049
1051
  questionsGenerated++;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@programisto/edrm-exams",
4
- "version": "0.3.5",
4
+ "version": "0.3.7",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },