@programisto/edrm-exams 0.3.1 → 0.3.3
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.
|
@@ -250,7 +250,7 @@ class ExamsRouter extends EnduranceRouter {
|
|
|
250
250
|
// Modifier un test
|
|
251
251
|
this.put('/test/:id', authenticatedOptions, async (req, res) => {
|
|
252
252
|
const { id } = req.params;
|
|
253
|
-
const { title, description, targetJob, seniorityLevel, categories, state } = req.body;
|
|
253
|
+
const { title, description, targetJob, seniorityLevel, categories, state, questions } = req.body;
|
|
254
254
|
try {
|
|
255
255
|
const test = await Test.findById(id);
|
|
256
256
|
if (!test) {
|
|
@@ -291,6 +291,23 @@ class ExamsRouter extends EnduranceRouter {
|
|
|
291
291
|
}));
|
|
292
292
|
test.categories = processedCategories;
|
|
293
293
|
}
|
|
294
|
+
if (questions) {
|
|
295
|
+
// Vérifier que toutes les questions existent
|
|
296
|
+
const questionIds = questions.map((q) => q.questionId);
|
|
297
|
+
const existingQuestions = await TestQuestion.find({ _id: { $in: questionIds } });
|
|
298
|
+
if (existingQuestions.length !== questionIds.length) {
|
|
299
|
+
return res.status(400).json({
|
|
300
|
+
message: 'Certaines questions spécifiées n\'existent pas',
|
|
301
|
+
providedQuestions: questionIds.length,
|
|
302
|
+
foundQuestions: existingQuestions.length
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
// Mettre à jour les questions avec leur ordre
|
|
306
|
+
test.questions = questions.map((q) => ({
|
|
307
|
+
questionId: q.questionId,
|
|
308
|
+
order: q.order || 0
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
294
311
|
await test.save();
|
|
295
312
|
res.status(200).json({ message: 'Test modifié avec succès', data: test });
|
|
296
313
|
}
|
|
@@ -1304,6 +1321,22 @@ class ExamsRouter extends EnduranceRouter {
|
|
|
1304
1321
|
res.status(500).json({ message: 'Erreur interne du serveur' });
|
|
1305
1322
|
}
|
|
1306
1323
|
});
|
|
1324
|
+
// Supprimer un test result
|
|
1325
|
+
this.delete('/result/:id', authenticatedOptions, async (req, res) => {
|
|
1326
|
+
const { id } = req.params;
|
|
1327
|
+
try {
|
|
1328
|
+
const testResult = await TestResult.findById(id);
|
|
1329
|
+
if (!testResult) {
|
|
1330
|
+
return res.status(404).json({ message: 'TestResult not found' });
|
|
1331
|
+
}
|
|
1332
|
+
await TestResult.findByIdAndDelete(id);
|
|
1333
|
+
res.status(200).json({ message: 'TestResult deleted with success' });
|
|
1334
|
+
}
|
|
1335
|
+
catch (err) {
|
|
1336
|
+
console.error('error when deleting testResult : ', err);
|
|
1337
|
+
res.status(500).json({ message: 'Internal server error' });
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1307
1340
|
}
|
|
1308
1341
|
}
|
|
1309
1342
|
const router = new ExamsRouter();
|
package/package.json
CHANGED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { EnduranceRouter, EnduranceAuthMiddleware } from '@programisto/endurance-core';
|
|
2
|
-
import UserExam from '../models/user.model.js';
|
|
3
|
-
class UserRouter extends EnduranceRouter {
|
|
4
|
-
constructor() {
|
|
5
|
-
super(EnduranceAuthMiddleware.getInstance());
|
|
6
|
-
}
|
|
7
|
-
setupRoutes() {
|
|
8
|
-
const authenticatedOptions = {
|
|
9
|
-
requireAuth: false,
|
|
10
|
-
permissions: []
|
|
11
|
-
};
|
|
12
|
-
// Lister tous les utilisateurs
|
|
13
|
-
this.get('/', authenticatedOptions, async (req, res) => {
|
|
14
|
-
try {
|
|
15
|
-
const users = await UserExam.find();
|
|
16
|
-
res.status(200).json({ array: users });
|
|
17
|
-
}
|
|
18
|
-
catch (err) {
|
|
19
|
-
console.error('Error when retrieving users: ', err);
|
|
20
|
-
res.status(500).json({ message: 'Internal server error' });
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
// Créer un utilisateur
|
|
24
|
-
this.post('/create', authenticatedOptions, async (req, res) => {
|
|
25
|
-
const { firstName, lastName, email, companyId } = req.body;
|
|
26
|
-
if (!firstName || !lastName || !email || !companyId) {
|
|
27
|
-
return res.status(400).json({ message: 'Error, firstName, lastName, email and companyId are required' });
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
const newUser = new UserExam({ firstName, lastName, email, companyId });
|
|
31
|
-
await newUser.save();
|
|
32
|
-
res.status(201).json({ message: 'user created with sucess', user: newUser });
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
console.error('error when creating user : ', err);
|
|
36
|
-
res.status(500).json({ message: 'Internal server error' });
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
// Obtenir un utilisateur par son ID
|
|
40
|
-
this.get('/:id', authenticatedOptions, async (req, res) => {
|
|
41
|
-
const { id } = req.params;
|
|
42
|
-
try {
|
|
43
|
-
const user = await UserExam.findById(id);
|
|
44
|
-
if (!user) {
|
|
45
|
-
return res.status(404).json({ message: 'no user founded with this id' });
|
|
46
|
-
}
|
|
47
|
-
res.status(200).json({ data: user });
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
console.error('error when geting user : ', err);
|
|
51
|
-
res.status(500).json({ message: 'Internal server error' });
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
// Mettre à jour un utilisateur
|
|
55
|
-
this.put('/:id', authenticatedOptions, async (req, res) => {
|
|
56
|
-
const { id } = req.params;
|
|
57
|
-
const { firstName, lastName, email, companyId } = req.body;
|
|
58
|
-
try {
|
|
59
|
-
const user = await UserExam.findById(id);
|
|
60
|
-
if (!user) {
|
|
61
|
-
return res.status(404).json({ message: 'no user founded with this id' });
|
|
62
|
-
}
|
|
63
|
-
const updateData = {
|
|
64
|
-
firstName: firstName || user.firstName,
|
|
65
|
-
lastName: lastName || user.lastName,
|
|
66
|
-
email: email || user.email,
|
|
67
|
-
companyId: companyId || user.companyId
|
|
68
|
-
};
|
|
69
|
-
await UserExam.findByIdAndUpdate(id, updateData, { new: true });
|
|
70
|
-
const updatedUser = await UserExam.findById(id);
|
|
71
|
-
res.status(200).json({ message: 'user updated', user: updatedUser });
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
console.error('error when updating user : ', err);
|
|
75
|
-
res.status(500).json({ message: 'Internal server error' });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
// Supprimer un utilisateur
|
|
79
|
-
this.delete('/:id', authenticatedOptions, async (req, res) => {
|
|
80
|
-
const { id } = req.params;
|
|
81
|
-
try {
|
|
82
|
-
const user = await UserExam.findByIdAndDelete(id);
|
|
83
|
-
if (!user) {
|
|
84
|
-
return res.status(404).json({ message: 'no user founded with this id' });
|
|
85
|
-
}
|
|
86
|
-
res.status(200).json({ message: 'user deleted', user });
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
console.error('error when deleting user : ', err);
|
|
90
|
-
res.status(500).json({ message: 'Internal server error' });
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const router = new UserRouter();
|
|
96
|
-
export default router;
|