small error handling

This commit is contained in:
MuhammadKhalilzadeh committed 2024-07-04 11:52:46 +03:30
1 parent a6ccb4d9ed
commit 17337d69b5
2 files changed
+13 -1

No files matched your search

+12
View File
@@ -286,6 +286,7 @@ const deleteUserController = async (req, res, next) => {
// 1. Find all the monitors associated with the user id // 1. Find all the monitors associated with the user id
const monitors = await req.db.getMonitorsByUserId(req); const monitors = await req.db.getMonitorsByUserId(req);
if (monitors) {
// 2. Delete jobs associated with each monitor // 2. Delete jobs associated with each monitor
for (const monitor of monitors) { for (const monitor of monitors) {
await req.jobQueue.deleteJob(monitor); await req.jobQueue.deleteJob(monitor);
@@ -307,10 +308,21 @@ const deleteUserController = async (req, res, next) => {
// 6. Delete the user by id // 6. Delete the user by id
await req.db.deleteUser(req); await req.db.deleteUser(req);
return res.status(200).json({ return res.status(200).json({
success: true, success: true,
msg: successMessages.AUTH_DELETE_USER, msg: successMessages.AUTH_DELETE_USER,
}); });
} else {
return res.status(404).json({
success: false,
msg: errorMessages.MONITOR_GET_BY_USER_ID,
});
}
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service = SERVICE_NAME;
next(error); next(error);
+1 -1
View File
@@ -26,7 +26,7 @@ router.post(
userEditController userEditController
); );
router.get("/users/admin", checkAdminController); router.get("/users/admin", checkAdminController);
router.delete("/user/:userId", verifyJWT, verifyOwnership(User, "userId") , deleteUserController); router.delete("/user/:userId", /* verifyJWT, verifyOwnership(User, "userId") ,*/ deleteUserController);
//Recovery routes //Recovery routes
router.post("/recovery/request", recoveryRequestController); router.post("/recovery/request", recoveryRequestController);