Skip to content

Commit

Permalink
Removed redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
neerajsunil committed Sep 25, 2024
1 parent ea26d35 commit b0dc91c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
18 changes: 1 addition & 17 deletions Server/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,23 +466,7 @@ const issueToken = (payload) => {
const result = await req.db.getMonitorsByTeamId({
params: { teamId: user.teamId },
});
if (user.role.includes("superadmin") && result?.monitors.length > 0) {
//2. Remove all jobs, delete checks and alerts
await Promise.all(
monitors.map(async (monitor) => {
await req.jobQueue.deleteJob(monitor);

await req.db.deleteChecks(monitor._id);
await req.db.deleteAlertByMonitorId(monitor._id);
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
await req.db.deleteNotificationsByMonitorId(monitor._id);
})
);

// 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({
Expand Down
27 changes: 0 additions & 27 deletions Server/utils/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,18 @@ const errorMessages = {
DB_TOKEN_NOT_FOUND: "Token not found",
DB_RESET_PASSWORD_BAD_MATCH:
"New password must be different from old password",
DB_FIND_MONTIOR_BY_ID: (monitorId) =>
`Monitor with id ${monitorId} not found`,
DB_DELETE_CHECKS: (monitorId) =>
`No checks found for monitor with id ${monitorId}`,
DB_DELETE_ALERT: (alertId) => `Alert with id ${alertId} not found`,

//Auth errors
AUTH_INCORRECT_PASSWORD: "Incorrect password",
AUTH_UNAUTHORIZED: "Unauthorized access",

// Monitor Errros
MONITOR_GET_BY_ID: "Monitor not found",
MONITOR_GET_BY_USER_ID: "No monitors found for user",

// Job Queue Errors
JOB_QUEUE_WORKER_CLOSE: "Error closing worker",
JOB_QUEUE_DELETE_JOB: "Job not found in queue",
JOB_QUEUE_OBLITERATE: "Error obliterating queue",
};

const successMessages = {
//Alert Controller
ALERT_CREATE: "Alert created successfully",
ALERT_GET_BY_USER: "Got alerts successfully",
ALERT_GET_BY_MONITOR: "Got alerts by Monitor successfully",
ALERT_GET_BY_ID: "Got alert by Id successfully",
ALERT_EDIT: "Alert edited successfully",
ALERT_DELETE: "Alert deleted successfully",

// Auth Controller
AUTH_CREATE_USER: "User created successfully",
AUTH_LOGIN_USER: "User logged in successfully",
Expand All @@ -68,16 +51,6 @@ const errorMessages = {
CHECK_GET: "Got checks successfully",
CHECK_DELETE: "Checks deleted successfully",

//Monitor Controller
MONITOR_GET_ALL: "Got all monitors successfully",
MONTIOR_STATS_BY_ID: "Got monitor stats by Id successfully",
MONTIOR_GET_BY_ID: "Got monitor by Id successfully",
MONITOR_GET_BY_USER_ID: (userId) => `Got monitor for ${userId} successfully"`,
MONITOR_CREATE: "Monitor created successfully",
MONITOR_DELETE: "Monitor deleted successfully",
MONITOR_EDIT: "Monitor edited successfully",
MONITOR_CERTIFICATE: "Got monitor certificate successfully",

//Job Queue
JOB_QUEUE_DELETE_JOB: "Job removed successfully",
JOB_QUEUE_OBLITERATE: "Queue OBLITERATED!!!",
Expand Down

0 comments on commit b0dc91c

Please sign in to comment.