fix delete user method
This commit is contained in:
1 parent
0598a08f34
commit
7526fe2a68
1 file changed
+11
-17
@@ -465,11 +465,10 @@ 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({
|
const result = await req.db.getMonitorsByTeamId({
|
||||||
params: { userId: _id },
|
params: { teamId: user.teamId },
|
||||||
});
|
});
|
||||||
|
if (result?.monitors.length > 0) {
|
||||||
if (monitors) {
|
|
||||||
//2. Remove all jobs, delete checks and alerts
|
//2. Remove all jobs, delete checks and alerts
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
monitors.map(async (monitor) => {
|
monitors.map(async (monitor) => {
|
||||||
@@ -484,22 +483,17 @@ const deleteUserController = async (req, res, next) => {
|
|||||||
|
|
||||||
// 3. Delete each monitor
|
// 3. Delete each monitor
|
||||||
await req.db.deleteMonitorsByUserId(user._id);
|
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) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
|
error.method === undefined && error.method === "deleteUserController";
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user