diff --git a/server/model/monitor.js b/server/model/monitor.js index 00da052f..d5dc1d90 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -103,6 +103,10 @@ class Monitor extends BeanModel { return data; } + /** + * Get all tags applied to this monitor + * @returns {Promise[]>} + */ async getTags() { return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]); } @@ -116,6 +120,10 @@ class Monitor extends BeanModel { return Buffer.from(user + ":" + pass).toString("base64"); } + /** + * Is the TLS expiry notification enabled? + * @returns {boolean} + */ isEnabledExpiryNotification() { return Boolean(this.expiryNotification); } @@ -507,6 +515,7 @@ class Monitor extends BeanModel { }; + /** Get a heartbeat and handle errors */ const safeBeat = async () => { try { await beat(); @@ -540,6 +549,10 @@ class Monitor extends BeanModel { this.prometheus().remove(); } + /** + * Get a new prometheus instance + * @returns {Prometheus} + */ prometheus() { return new Prometheus(this); } diff --git a/server/model/proxy.js b/server/model/proxy.js index 7ddec434..34a55d2f 100644 --- a/server/model/proxy.js +++ b/server/model/proxy.js @@ -1,6 +1,10 @@ const { BeanModel } = require("redbean-node/dist/bean-model"); class Proxy extends BeanModel { + /** + * Return a object that ready to parse to JSON + * @returns {Object} + */ toJSON() { return { id: this._id, diff --git a/server/model/status_page.js b/server/model/status_page.js index b1befc25..605bdd3e 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -6,6 +6,7 @@ class StatusPage extends BeanModel { static domainMappingList = { }; /** + * Loads domain mapping from DB * Return object like this: { "test-uptime.kuma.pet": "default" } * @returns {Promise} */ @@ -17,6 +18,12 @@ class StatusPage extends BeanModel { `); } + /** + * Send status page list to client + * @param {Server} io io Socket server instance + * @param {Socket} socket Socket.io instance + * @returns {Promise} + */ static async sendStatusPageList(io, socket) { let result = {}; @@ -30,6 +37,11 @@ class StatusPage extends BeanModel { return list; } + /** + * Update list of domain names + * @param {Array} domainNameList + * @returns {Promise} + */ async updateDomainNameList(domainNameList) { if (!Array.isArray(domainNameList)) { @@ -69,6 +81,10 @@ class StatusPage extends BeanModel { } } + /** + * Get list of domain names + * @returns {Array} + */ getDomainNameList() { let domainList = []; for (let domain in StatusPage.domainMappingList) { @@ -81,6 +97,10 @@ class StatusPage extends BeanModel { return domainList; } + /** + * Return a object that ready to parse to JSON + * @returns {Object} + */ async toJSON() { return { id: this.id, @@ -98,6 +118,11 @@ class StatusPage extends BeanModel { }; } + /** + * Return a object that ready to parse to JSON for public + * Only show necessary data to public + * @returns {Object} + */ async toPublicJSON() { return { slug: this.slug, @@ -113,12 +138,20 @@ class StatusPage extends BeanModel { }; } + /** + * Convert slug to status page ID + * @param {string} slug + */ static async slugToID(slug) { return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [ slug ]); } + /** + * Get path to the icon for the page + * @returns {string} + */ getIcon() { if (!this.icon) { return "/icon.svg"; diff --git a/server/model/user.js b/server/model/user.js index b243f87f..fc619c74 100644 --- a/server/model/user.js +++ b/server/model/user.js @@ -3,12 +3,11 @@ const passwordHash = require("../password-hash"); const { R } = require("redbean-node"); class User extends BeanModel { - /** - * + * Reset user password * Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead. - * @param userID - * @param newPassword + * @param {number} userID ID of user to update + * @param {string} newPassword * @returns {Promise} */ static async resetPassword(userID, newPassword) { @@ -19,8 +18,8 @@ class User extends BeanModel { } /** - * - * @param newPassword + * Reset this users password + * @param {string} newPassword * @returns {Promise} */ async resetPassword(newPassword) {