@programisto/edrm-exams 0.3.5 → 0.3.6
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
|
}
|