fixes
This commit is contained in:
1 parent
22448e05d3
commit
704980045d
4 files changed
+13
-5
No files matched your search
@@ -7,6 +7,7 @@ const {
|
|||||||
recoveryValidation,
|
recoveryValidation,
|
||||||
recoveryTokenValidation,
|
recoveryTokenValidation,
|
||||||
newPasswordValidation,
|
newPasswordValidation,
|
||||||
|
userDeleteValidation
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
@@ -238,7 +239,7 @@ const resetPasswordController = async (req, res, next) => {
|
|||||||
const deleteUserController = async (req, res, next) => {
|
const deleteUserController = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
// Validate user
|
// Validate user
|
||||||
await editUserParamValidation.userDeleteValidation(req.params.userId);
|
await userDeleteValidation.validateAsync(req.params.userId);
|
||||||
|
|
||||||
// Check if the user exists
|
// Check if the user exists
|
||||||
const user = await req.db.getUserById(req.params.userId);
|
const user = await req.db.getUserById(req.params.userId);
|
||||||
@@ -250,9 +251,11 @@ const deleteUserController = async (req, res, next) => {
|
|||||||
const monitors = await req.db.getMonitorsByUserId(req.params.userId);
|
const monitors = await req.db.getMonitorsByUserId(req.params.userId);
|
||||||
|
|
||||||
// Step 2: For each monitor, delete all associated checks and alerts
|
// Step 2: For each monitor, delete all associated checks and alerts
|
||||||
for (const monitor of monitors) {
|
if (monitors) {
|
||||||
await req.db.deleteChecks(monitor.id);
|
for (const monitor of monitors) {
|
||||||
await req.db.deleteAlertByMonitorId(monitor.id);
|
await req.db.deleteChecks(monitor.id);
|
||||||
|
await req.db.deleteAlertByMonitorId(monitor.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Delete all monitors associated with the user
|
// Step 3: Delete all monitors associated with the user
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ const getChecks = async (monitorId) => {
|
|||||||
const deleteChecks = async (monitorId) => {
|
const deleteChecks = async (monitorId) => {
|
||||||
try {
|
try {
|
||||||
const result = await Check.deleteMany({ monitorId });
|
const result = await Check.deleteMany({ monitorId });
|
||||||
return result.deletedCount;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const {
|
|||||||
recoveryRequestController,
|
recoveryRequestController,
|
||||||
validateRecoveryTokenController,
|
validateRecoveryTokenController,
|
||||||
resetPasswordController,
|
resetPasswordController,
|
||||||
|
deleteUserController
|
||||||
} = require("../controllers/authController");
|
} = require("../controllers/authController");
|
||||||
|
|
||||||
//Auth routes
|
//Auth routes
|
||||||
@@ -20,4 +21,7 @@ router.post("/recovery/request", recoveryRequestController);
|
|||||||
router.post("/recovery/validate", validateRecoveryTokenController);
|
router.post("/recovery/validate", validateRecoveryTokenController);
|
||||||
router.post("/recovery/reset/", resetPasswordController);
|
router.post("/recovery/reset/", resetPasswordController);
|
||||||
|
|
||||||
|
//Delete routes
|
||||||
|
router.delete("/delete/:userId", deleteUserController);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -162,4 +162,5 @@ module.exports = {
|
|||||||
createCheckBodyValidation,
|
createCheckBodyValidation,
|
||||||
getChecksParamValidation,
|
getChecksParamValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
|
userDeleteValidation
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user