mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-13 21:29:46 -06:00
fixes
This commit is contained in:
@@ -7,6 +7,7 @@ const {
|
||||
recoveryValidation,
|
||||
recoveryTokenValidation,
|
||||
newPasswordValidation,
|
||||
userDeleteValidation
|
||||
} = require("../validation/joi");
|
||||
const logger = require("../utils/logger");
|
||||
require("dotenv").config();
|
||||
@@ -238,7 +239,7 @@ const resetPasswordController = async (req, res, next) => {
|
||||
const deleteUserController = async (req, res, next) => {
|
||||
try {
|
||||
// Validate user
|
||||
await editUserParamValidation.userDeleteValidation(req.params.userId);
|
||||
await userDeleteValidation.validateAsync(req.params.userId);
|
||||
|
||||
// Check if the user exists
|
||||
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);
|
||||
|
||||
// Step 2: For each monitor, delete all associated checks and alerts
|
||||
for (const monitor of monitors) {
|
||||
await req.db.deleteChecks(monitor.id);
|
||||
await req.db.deleteAlertByMonitorId(monitor.id);
|
||||
if (monitors) {
|
||||
for (const monitor of monitors) {
|
||||
await req.db.deleteChecks(monitor.id);
|
||||
await req.db.deleteAlertByMonitorId(monitor.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Delete all monitors associated with the user
|
||||
|
||||
@@ -396,7 +396,7 @@ const getChecks = async (monitorId) => {
|
||||
const deleteChecks = async (monitorId) => {
|
||||
try {
|
||||
const result = await Check.deleteMany({ monitorId });
|
||||
return result.deletedCount;
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ const {
|
||||
recoveryRequestController,
|
||||
validateRecoveryTokenController,
|
||||
resetPasswordController,
|
||||
deleteUserController
|
||||
} = require("../controllers/authController");
|
||||
|
||||
//Auth routes
|
||||
@@ -20,4 +21,7 @@ router.post("/recovery/request", recoveryRequestController);
|
||||
router.post("/recovery/validate", validateRecoveryTokenController);
|
||||
router.post("/recovery/reset/", resetPasswordController);
|
||||
|
||||
//Delete routes
|
||||
router.delete("/delete/:userId", deleteUserController);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -162,4 +162,5 @@ module.exports = {
|
||||
createCheckBodyValidation,
|
||||
getChecksParamValidation,
|
||||
deleteChecksParamValidation,
|
||||
userDeleteValidation
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user