ronantakizawa/codereview-bench huggingface dataset:
Repository: louislam/uptime-kuma
File: src/components/notifications/Whapi.vue (Vue)

Code before:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <input id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-to-number" class="form-label">{{ $t("Phone number") }}</label>
        <input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{10,31}$" class="form-control" required>
        <i18n-t tag="div" keypath="wayToWriteWhapiPhoneNumber" class="form-text"></i18n-t>
    </div>

    <div class="mb-3">
        <i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
            <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
        </i18n-t>
    </div>
</template>


Review comment (suggestion):
in this translation you are adding a bottom margin (`mb-3`) and are adding a top margin (`margin-top: 8px`)

Please only use one of these.
Also consider if this can be merged with the outer `div`

Code after:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" placeholder="https://gate.whapi.cloud/" type="text" class="form-control">
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput>
        <i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text">
            <a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a>
        </i18n-t>
    </div>

    <div class="mb-3">
        <label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label>
        <input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
        <div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "00117612345678@s.whatsapp.net", "123456789012345678@g.us"]) }}</div>
    </div>

    <i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
        <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
    </i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";

export default {
    components: {
        HiddenInput,
    }
};
</script>
Repository: louislam/uptime-kuma
File: src/components/notifications/Whapi.vue (Vue)

Code before:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <input id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" type="text" class="form-control" required>
    </div>

    <div class="mb-3">
        <label for="whapi-to-number" class="form-label">{{ $t("Phone number") }}</label>
        <input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{10,31}$" class="form-control" required>
        <i18n-t tag="div" keypath="wayToWriteWhapiPhoneNumber" class="form-text"></i18n-t>
    </div>

    <div class="mb-3">
        <i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
            <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
        </i18n-t>
    </div>
</template>


Review comment (bug):
idk if 10 is a small enough choice:

https://stackoverflow.com/questions/14894899/what-is-the-minimum-length-of-a-valid-international-phone-number

```suggestion
        <input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{8,31}$" class="form-control" required>
```

Code after:
<template>
    <div class="mb-3">
        <label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
        <input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" placeholder="https://gate.whapi.cloud/" type="text" class="form-control">
    </div>

    <div class="mb-3">
        <label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
        <HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput>
        <i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text">
            <a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a>
        </i18n-t>
    </div>

    <div class="mb-3">
        <label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label>
        <input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
        <div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "00117612345678@s.whatsapp.net", "123456789012345678@g.us"]) }}</div>
    </div>

    <i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
        <a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
    </i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";

export default {
    components: {
        HiddenInput,
    }
};
</script>
Repository: louislam/uptime-kuma
File: server/notification-providers/whapi.js (JavaScript)

Code before:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class Whapi extends NotificationProvider {

    name = "whapi";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {

        let okMsg = "Sent Successfully.";

        try {

            const config = {
                headers: {
                    "Accept": "application/json",
                    "Content-Type": "application/json",
                    "Authorization": "Bearer " + notification.whapiAuthToken,
                }
            };

            let data = {
                "to": notification.whapiRecipient,
                "body": msg,
            };

            let url = (notification.whapiApiUrl || "https://gate.whapi.cloud/").replace(/\/+$/, "") + "/messages/text";

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

Review comment (suggestion):
```suggestion
        const okMsg = "Sent Successfully.";
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class Whapi extends NotificationProvider {
    name = "whapi";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        try {
            const config = {
                headers: {
                    "Accept": "application/json",
                    "Content-Type": "application/json",
                    "Authorization": "Bearer " + notification.whapiAuthToken,
                }
            };

            let data = {
                "to": notification.whapiRecipient,
                "body": msg,
            };

            let url = (notification.whapiApiUrl || "https://gate.whapi.cloud/").replace(/\/+$/, "") + "/messages/text";

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

}
Repository: louislam/uptime-kuma
File: server/monitor-types/mongodb.js (JavaScript)

Code before:
const { MonitorType } = require("./monitor-type");
const { UP } = require("../../src/util");
const { MongoClient } = require("mongodb");
const jsonata = require("jsonata");

class MongodbMonitorType extends MonitorType {

    name = "mongodb";

    /**
     * @inheritdoc
     */
    async check(monitor, heartbeat, _server) {
        let command = { "ping": 1 };

        if (monitor.databaseQuery) {
            command = JSON.parse(monitor.databaseQuery);
        }

        let result = await this.runMongodbCommand(monitor.databaseConnectionString, command);

        if (result["ok"] !== 1) {
            throw new Error("MongoDB command failed");
        }

        if (monitor.jsonPath) {
            let expression = jsonata(monitor.jsonPath);
            result = await expression.evaluate(result);
            if (!result) {
                throw new Error("Queried value not found.");
            }
        }

        if (monitor.expectedValue) {
            if (result.toString() === monitor.expectedValue) {
                heartbeat.msg = "Expected value found";
                heartbeat.status = UP;
            } else {
                throw new Error("Query executed, but value is not equal to expected value, value was: [" + JSON.stringify(result) + "]");
            }

Review comment (suggestion):
nit: This way this is a bit closer

```suggestion
```

Code after:
const { MonitorType } = require("./monitor-type");
const { UP } = require("../../src/util");
const { MongoClient } = require("mongodb");
const jsonata = require("jsonata");

class MongodbMonitorType extends MonitorType {

    name = "mongodb";

    /**
     * @inheritdoc
     */
    async check(monitor, heartbeat, _server) {
        let command = { "ping": 1 };
        if (monitor.databaseQuery) {
            command = JSON.parse(monitor.databaseQuery);
        }

        let result = await this.runMongodbCommand(monitor.databaseConnectionString, command);

        if (result["ok"] !== 1) {
            throw new Error("MongoDB command failed");
        } else {
            heartbeat.msg = "Command executed successfully";
        }

        if (monitor.jsonPath) {
            let expression = jsonata(monitor.jsonPath);
            result = await expression.evaluate(result);
            if (result) {
                heartbeat.msg = "Command executed successfully and the jsonata expression produces a result.";
            } else {
                throw new Error("Queried value not found.");
            }
        }

        if (monitor.expectedValue) {
            if (result.toString() === monitor.expectedValue) {
                heartbeat.msg = "Command executed successfully and expected value was found";
            } else {
Repository: louislam/uptime-kuma
File: server/model/monitor.js (JavaScript)

Code before:
            SELECT parent.* FROM monitor parent
    		LEFT JOIN monitor child
    			ON child.parent = parent.id
            WHERE child.id = ?
        `, [
            monitorID,
        ]);
    }

    /**
     * Gets all Children of the monitor
     * @param {number} monitorID ID of monitor to get
     * @returns {Promise<LooseObject<any>>} Children
     */
    static async getChildren(monitorID) {
        return await R.getAll(`
            SELECT * FROM monitor
            WHERE parent = ?
        `, [
            monitorID,
        ]);
    }

    /**
     * Gets Full Path as array (Groups and Name)
     * @returns {Promise<string[]>} Full path as array of this monitor
     */
    async getPath() {
        const path = [ this.name ];

        if (this.parent === null) {
            return path;
        }

        let parent = await Monitor.getParent(this.id);
        while (parent !== null) {
            path.unshift(parent.name);
            parent = await Monitor.getParent(parent.id);
        }

        return path;
    }

    /**
     * Gets recursive all child ids
     * @param {number} monitorID ID of the monitor to get
     * @returns {Promise<Array>} IDs of all children
     */
    static async getAllChildrenIDs(monitorID) {
        const childs = await Monitor.getChildren(monitorID);


Review comment (suggestion):
nit: gramar/rewording

```suggestion
     * Gets the full path
     * @returns {Promise<string[]>} Full path (inludes groups and the name) of the monitor
```

Code after:
            SELECT parent.* FROM monitor parent
    		LEFT JOIN monitor child
    			ON child.parent = parent.id
            WHERE child.id = ?
        `, [
            monitorID,
        ]);
    }

    /**
     * Gets all Children of the monitor
     * @param {number} monitorID ID of monitor to get
     * @returns {Promise<LooseObject<any>>} Children
     */
    static async getChildren(monitorID) {
        return await R.getAll(`
            SELECT * FROM monitor
            WHERE parent = ?
        `, [
            monitorID,
        ]);
    }

    /**
     * Gets the full path
     * @returns {Promise<string[]>} Full path (includes groups and the name) of the monitor
     */
    async getPath() {
        const path = [ this.name ];

        if (this.parent === null) {
            return path;
        }

        let parent = await Monitor.getParent(this.id);
        while (parent !== null) {
            path.unshift(parent.name);
            parent = await Monitor.getParent(parent.id);
        }

        return path;
    }

    /**
     * Gets recursive all child ids
     * @param {number} monitorID ID of the monitor to get
     * @returns {Promise<Array>} IDs of all children
     */
    static async getAllChildrenIDs(monitorID) {
        const childs = await Monitor.getChildren(monitorID);
Repository: louislam/uptime-kuma
File: server/notification-providers/gtx-messaging.js (JavaScript)

Code before:

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        let authKey = notification.gtxMessagingApiKey;
        let from = notification.gtxMessagingFrom.trim();
        let to = notification.gtxMessagingTo.trim();
        let text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {

            let data = new URLSearchParams();
            data.append("from", from);
            data.append("to", to);
            data.append("text", text);

            let url = `https://rest.gtx-messaging.net/smsc/sendsms/${authKey}/json`;

            console.log(`will post url: ${url}, data:`, data);

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;


Review comment (bug):
You forgot to delete this debug statement.

```suggestion
```

Code after:

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        // The UP/DOWN symbols will be replaced with `???` by gtx-messaging
        const text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {
            const data = new URLSearchParams();
            data.append("from", notification.gtxMessagingFrom.trim());
            data.append("to", notification.gtxMessagingTo.trim());
            data.append("text", text);

            const url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;
Repository: louislam/uptime-kuma
File: server/notification-providers/gtx-messaging.js (JavaScript)

Code before:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        let authKey = notification.gtxMessagingApiKey;
        let from = notification.gtxMessagingFrom.trim();
        let to = notification.gtxMessagingTo.trim();
        let text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {

            let data = new URLSearchParams();
            data.append("from", from);
            data.append("to", to);
            data.append("text", text);

            let url = `https://rest.gtx-messaging.net/smsc/sendsms/${authKey}/json`;

            console.log(`will post url: ${url}, data:`, data);

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;


Review comment (suggestion):
If something is not mutated, please prefer `const` 

This includes the inlined variable from above

```suggestion
            const url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        // The UP/DOWN symbols will be replaced with `???` by gtx-messaging
        const text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {
            const data = new URLSearchParams();
            data.append("from", notification.gtxMessagingFrom.trim());
            data.append("to", notification.gtxMessagingTo.trim());
            data.append("text", text);

            const url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;
Repository: louislam/uptime-kuma
File: server/notification-providers/gtx-messaging.js (JavaScript)

Code before:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        let authKey = notification.gtxMessagingApiKey;
        let from = notification.gtxMessagingFrom.trim();
        let to = notification.gtxMessagingTo.trim();
        let text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {

            let data = new URLSearchParams();
            data.append("from", from);
            data.append("to", to);
            data.append("text", text);

            let url = `https://rest.gtx-messaging.net/smsc/sendsms/${authKey}/json`;

            console.log(`will post url: ${url}, data:`, data);

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;


Review comment (suggestion):
If a variable name is not mutated, please prefer `const`

```suggestion
            const data = new URLSearchParams();
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        // The UP/DOWN symbols will be replaced with `???` by gtx-messaging
        const text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {
            const data = new URLSearchParams();
            data.append("from", notification.gtxMessagingFrom.trim());
            data.append("to", notification.gtxMessagingTo.trim());
            data.append("text", text);

            const url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;
Repository: louislam/uptime-kuma
File: server/notification-providers/gtx-messaging.js (JavaScript)

Code before:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        let authKey = notification.gtxMessagingApiKey;
        let from = notification.gtxMessagingFrom.trim();
        let to = notification.gtxMessagingTo.trim();
        let text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {

            let data = new URLSearchParams();
            data.append("from", from);
            data.append("to", to);
            data.append("text", text);

            let url = `https://rest.gtx-messaging.net/smsc/sendsms/${authKey}/json`;

            console.log(`will post url: ${url}, data:`, data);

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;


Review comment (suggestion):
see above

```suggestion
            let url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
    name = "gtxmessaging";

    /**
     * @inheritDoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        // The UP/DOWN symbols will be replaced with `???` by gtx-messaging
        const text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

        try {
            const data = new URLSearchParams();
            data.append("from", notification.gtxMessagingFrom.trim());
            data.append("to", notification.gtxMessagingTo.trim());
            data.append("text", text);

            const url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;

            await axios.post(url, data);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = GtxMessaging;