Updated server/model/* JSDoc to match new methods

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
This commit is contained in:
Matthew Nickson 2022-04-21 18:30:04 +01:00
parent 4ddbf71920
commit 0083485d4c
No known key found for this signature in database
GPG Key ID: BF229DCFD4748E05
4 changed files with 55 additions and 6 deletions

View File

@ -103,6 +103,10 @@ class Monitor extends BeanModel {
return data; return data;
} }
/**
* Get all tags applied to this monitor
* @returns {Promise<LooseObject<any>[]>}
*/
async getTags() { 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 ]); 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"); return Buffer.from(user + ":" + pass).toString("base64");
} }
/**
* Is the TLS expiry notification enabled?
* @returns {boolean}
*/
isEnabledExpiryNotification() { isEnabledExpiryNotification() {
return Boolean(this.expiryNotification); return Boolean(this.expiryNotification);
} }
@ -507,6 +515,7 @@ class Monitor extends BeanModel {
}; };
/** Get a heartbeat and handle errors */
const safeBeat = async () => { const safeBeat = async () => {
try { try {
await beat(); await beat();
@ -540,6 +549,10 @@ class Monitor extends BeanModel {
this.prometheus().remove(); this.prometheus().remove();
} }
/**
* Get a new prometheus instance
* @returns {Prometheus}
*/
prometheus() { prometheus() {
return new Prometheus(this); return new Prometheus(this);
} }

View File

@ -1,6 +1,10 @@
const { BeanModel } = require("redbean-node/dist/bean-model"); const { BeanModel } = require("redbean-node/dist/bean-model");
class Proxy extends BeanModel { class Proxy extends BeanModel {
/**
* Return a object that ready to parse to JSON
* @returns {Object}
*/
toJSON() { toJSON() {
return { return {
id: this._id, id: this._id,

View File

@ -6,6 +6,7 @@ class StatusPage extends BeanModel {
static domainMappingList = { }; static domainMappingList = { };
/** /**
* Loads domain mapping from DB
* Return object like this: { "test-uptime.kuma.pet": "default" } * Return object like this: { "test-uptime.kuma.pet": "default" }
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
@ -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<Bean[]>}
*/
static async sendStatusPageList(io, socket) { static async sendStatusPageList(io, socket) {
let result = {}; let result = {};
@ -30,6 +37,11 @@ class StatusPage extends BeanModel {
return list; return list;
} }
/**
* Update list of domain names
* @param {Array<string>} domainNameList
* @returns {Promise<void>}
*/
async updateDomainNameList(domainNameList) { async updateDomainNameList(domainNameList) {
if (!Array.isArray(domainNameList)) { if (!Array.isArray(domainNameList)) {
@ -69,6 +81,10 @@ class StatusPage extends BeanModel {
} }
} }
/**
* Get list of domain names
* @returns {Array<Object>}
*/
getDomainNameList() { getDomainNameList() {
let domainList = []; let domainList = [];
for (let domain in StatusPage.domainMappingList) { for (let domain in StatusPage.domainMappingList) {
@ -81,6 +97,10 @@ class StatusPage extends BeanModel {
return domainList; return domainList;
} }
/**
* Return a object that ready to parse to JSON
* @returns {Object}
*/
async toJSON() { async toJSON() {
return { return {
id: this.id, 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() { async toPublicJSON() {
return { return {
slug: this.slug, slug: this.slug,
@ -113,12 +138,20 @@ class StatusPage extends BeanModel {
}; };
} }
/**
* Convert slug to status page ID
* @param {string} slug
*/
static async slugToID(slug) { static async slugToID(slug) {
return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [ return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [
slug slug
]); ]);
} }
/**
* Get path to the icon for the page
* @returns {string}
*/
getIcon() { getIcon() {
if (!this.icon) { if (!this.icon) {
return "/icon.svg"; return "/icon.svg";

View File

@ -3,12 +3,11 @@ const passwordHash = require("../password-hash");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
class User extends BeanModel { 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. * Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
* @param userID * @param {number} userID ID of user to update
* @param newPassword * @param {string} newPassword
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
static async resetPassword(userID, newPassword) { static async resetPassword(userID, newPassword) {
@ -19,8 +18,8 @@ class User extends BeanModel {
} }
/** /**
* * Reset this users password
* @param newPassword * @param {string} newPassword
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async resetPassword(newPassword) { async resetPassword(newPassword) {