small error handling
This commit is contained in:
1 parent
a6ccb4d9ed
commit
17337d69b5
2 files changed
+36
-24
No files matched your search
@@ -286,31 +286,43 @@ 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);
|
||||||
|
|
||||||
// 2. Delete jobs associated with each monitor
|
if (monitors) {
|
||||||
for (const monitor of monitors) {
|
// 2. Delete jobs associated with each monitor
|
||||||
await req.jobQueue.deleteJob(monitor);
|
for (const monitor of monitors) {
|
||||||
|
await req.jobQueue.deleteJob(monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Delete all checks associated with each monitor
|
||||||
|
for (const monitor of monitors) {
|
||||||
|
await req.db.deleteChecks(monitor._id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Delete all alerts associated with each monitor
|
||||||
|
for (const monitor of monitors) {
|
||||||
|
await req.db.deleteAlertByMonitorId(monitor._id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Delete each monitor
|
||||||
|
await req.db.deleteMonitorsByUserId(user._id);
|
||||||
|
|
||||||
|
// 6. Delete the user by id
|
||||||
|
await req.db.deleteUser(req);
|
||||||
|
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: successMessages.AUTH_DELETE_USER,
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
msg: errorMessages.MONITOR_GET_BY_USER_ID,
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Delete all checks associated with each monitor
|
|
||||||
for (const monitor of monitors) {
|
|
||||||
await req.db.deleteChecks(monitor._id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Delete all alerts associated with each monitor
|
|
||||||
for (const monitor of monitors) {
|
|
||||||
await req.db.deleteAlertByMonitorId(monitor._id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Delete each monitor
|
|
||||||
await req.db.deleteMonitorsByUserId(user._id);
|
|
||||||
|
|
||||||
// 6. Delete the user by id
|
|
||||||
await req.db.deleteUser(req);
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
msg: successMessages.AUTH_DELETE_USER,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in new issue
Block a user