Repository: louislam/uptime-kuma
File: server/server.js (JavaScript)

Code before:
            log.debug("auth", "need auth");
        }

        socket.on("updateManual", async (data, callback) => {
            try {
                checkLogin(socket);

                let monitor = await R.findOne("monitor", " id = ? AND user_id = ? ", [
                    data.monitorID,
                    socket.userID,
                ]);

                if (!monitor) {
                    throw new Error("Monitor not found");
                }

                let status;
                if (data.status === 1) {
                    status = UP;
                } else if (data.status === 0) {
                    status = DOWN;
                } else if (data.status === 3) {
                    status = MAINTENANCE;
                } else {
                    status = PENDING;
                }

                monitor.manual_status = status;
                await R.store(monitor);

                callback({
                    ok: true,
                    msg: "Saved.",
                    msgi18n: true,
                    id: monitor.id,
                });

            } catch (e) {
                callback({
                    ok: true,
                    msg: e.message,
                });
            }
        });

    });

    log.debug("server", "Init the server");

    server.httpServer.once("error", async (err) => {
        log.error("server", "Cannot listen: " + err.message);

Review comment (suggestion):
Let's simply this:

```suggestion
                const status = [UP, DOWN, MAINTENANCE, PENDING].includes(data.status) ? data.status : PENDING;
```

Code after:
        } else {
            socket.emit("loginRequired");
            log.debug("auth", "need auth");
        }

    });

    log.debug("server", "Init the server");

    server.httpServer.once("error", async (err) => {
        log.error("server", "Cannot listen: " + err.message);
        await shutdownFunction();
        process.exit(1);
    });

    await server.start();

    server.httpServer.listen(port, hostname, async () => {
        if (hostname) {
            log.info("server", `Listening on ${hostname}:${port}`);
        } else {
            log.info("server", `Listening on ${port}`);
        }
        await startMonitors();

        // Put this here. Start background jobs after the db and server is ready to prevent clear up during db migration.
        await initBackgroundJobs();

        checkVersion.startInterval();
    });

    // Start cloudflared at the end if configured
    await cloudflaredAutoStart(cloudflaredToken);

})();

/**
 * Update notifications for a given monitor
 * @param {number} monitorID ID of monitor to update
 * @param {number[]} notificationIDList List of new notification
 * providers to add
 * @returns {Promise<void>}
 */
async function updateMonitorNotification(monitorID, notificationIDList) {
    await R.exec("DELETE FROM monitor_notification WHERE monitor_id = ? ", [
        monitorID,
    ]);

    for (let notificationID in notificationIDList) {
        if (notificationIDList[notificationID]) {
            let relation = R.dispense("monitor_notification");