@programisto/edrm-exams 0.3.0 → 0.3.2
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.
|
@@ -308,7 +308,7 @@ class ExamsRouter extends EnduranceRouter {
|
|
|
308
308
|
return res.status(404).json({ message: 'Test not found' });
|
|
309
309
|
}
|
|
310
310
|
for (let i = 0; i < test.questions.length; i++) {
|
|
311
|
-
await TestQuestion.findByIdAndDelete(test.questions[i]);
|
|
311
|
+
await TestQuestion.findByIdAndDelete(test.questions[i].questionId);
|
|
312
312
|
}
|
|
313
313
|
await TestResult.deleteMany({ testId: id });
|
|
314
314
|
await Test.findByIdAndDelete(id);
|
|
@@ -1304,6 +1304,22 @@ class ExamsRouter extends EnduranceRouter {
|
|
|
1304
1304
|
res.status(500).json({ message: 'Erreur interne du serveur' });
|
|
1305
1305
|
}
|
|
1306
1306
|
});
|
|
1307
|
+
// Supprimer un test result
|
|
1308
|
+
this.delete('/result/:id', authenticatedOptions, async (req, res) => {
|
|
1309
|
+
const { id } = req.params;
|
|
1310
|
+
try {
|
|
1311
|
+
const testResult = await TestResult.findById(id);
|
|
1312
|
+
if (!testResult) {
|
|
1313
|
+
return res.status(404).json({ message: 'TestResult not found' });
|
|
1314
|
+
}
|
|
1315
|
+
await TestResult.findByIdAndDelete(id);
|
|
1316
|
+
res.status(200).json({ message: 'TestResult deleted with success' });
|
|
1317
|
+
}
|
|
1318
|
+
catch (err) {
|
|
1319
|
+
console.error('error when deleting testResult : ', err);
|
|
1320
|
+
res.status(500).json({ message: 'Internal server error' });
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1307
1323
|
}
|
|
1308
1324
|
}
|
|
1309
1325
|
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;
|