fix delete user method

This commit is contained in:
Alex Holliday committed 2024-09-06 10:52:17 -07:00
1 parent 0598a08f34
commit 7526fe2a68
1 file changed
+11 -17
+11 -17
View File
@@ -465,11 +465,10 @@ const deleteUserController = async (req, res, next) => {
// 1. Find all the monitors associated with the user id
const monitors = await req.db.getMonitorsByUserId({
params: { userId: _id },
const result = await req.db.getMonitorsByTeamId({
params: { teamId: user.teamId },
});
if (monitors) {
if (result?.monitors.length > 0) {
//2. Remove all jobs, delete checks and alerts
await Promise.all(
monitors.map(async (monitor) => {
@@ -484,22 +483,17 @@ const deleteUserController = async (req, res, next) => {
// 3. Delete each monitor
await req.db.deleteMonitorsByUserId(user._id);
// 4. Delete the user by id
await req.db.deleteUser(user._id);
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,
});
}
// 4. Delete the user by id
await req.db.deleteUser(user._id);
return res.status(200).json({
success: true,
msg: successMessages.AUTH_DELETE_USER,
});
} catch (error) {
error.service = SERVICE_NAME;
error.method === undefined && error.method === "deleteUserController";
next(error);
}
};