mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-14 21:48:39 -05:00
delete functionality working
This commit is contained in:
@@ -7,7 +7,7 @@ const {
|
||||
recoveryValidation,
|
||||
recoveryTokenValidation,
|
||||
newPasswordValidation,
|
||||
userDeleteValidation
|
||||
deleteUserParamValidation
|
||||
} = require("../validation/joi");
|
||||
const logger = require("../utils/logger");
|
||||
require("dotenv").config();
|
||||
@@ -248,16 +248,16 @@ const resetPasswordController = async (req, res, next) => {
|
||||
const deleteUserController = async (req, res, next) => {
|
||||
try {
|
||||
// Validate user
|
||||
await userDeleteValidation.validateAsync(req.params.userId);
|
||||
await deleteUserParamValidation.validateAsync(req.body);
|
||||
|
||||
// Check if the user exists
|
||||
const user = await req.db.getUserById(req.params.userId);
|
||||
const user = await req.db.getUserByEmail(req);
|
||||
if (!user) {
|
||||
throw new Error(errorMessages.DB_USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 1. Find all the monitors associated with the user id
|
||||
const monitors = await req.db.getMonitorsByUserId(req.params.userId);
|
||||
const monitors = await req.db.getMonitorsByUserId(req);
|
||||
|
||||
// 2. Delete jobs associated with each monitor
|
||||
for (const monitor of monitors) {
|
||||
@@ -275,10 +275,10 @@ const deleteUserController = async (req, res, next) => {
|
||||
}
|
||||
|
||||
// 5. Delete each monitor
|
||||
await req.db.deleteMonitorsByUserId(req.params.userId);
|
||||
await req.db.deleteMonitorsByUserId(user._id);
|
||||
|
||||
// 6. Delete the user by id
|
||||
await req.db.deleteUserById(req.params.userId);
|
||||
await req.db.deleteUser(req);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
|
||||
@@ -15,7 +15,7 @@ const {
|
||||
router.post("/register", registerController);
|
||||
router.post("/login", loginController);
|
||||
router.post("/user/:userId", verifyJWT, userEditController);
|
||||
router.delete("/delete/:userId", deleteUserController);
|
||||
router.delete("/user/:userId", deleteUserController);
|
||||
|
||||
//Recovery routes
|
||||
router.post("/recovery/request", recoveryRequestController);
|
||||
|
||||
@@ -43,8 +43,8 @@ const newPasswordValidation = joi.object({
|
||||
confirm: joi.string(),
|
||||
});
|
||||
|
||||
const userDeleteValidation = joi.object({
|
||||
userId: joi.string().required(),
|
||||
const deleteUserParamValidation = joi.object({
|
||||
email: joi.string().email().required(),
|
||||
});
|
||||
|
||||
//****************************************
|
||||
@@ -162,5 +162,5 @@ module.exports = {
|
||||
createCheckBodyValidation,
|
||||
getChecksParamValidation,
|
||||
deleteChecksParamValidation,
|
||||
userDeleteValidation
|
||||
deleteUserParamValidation
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user