diff options
author | Daniel Baumann <daniel@debian.org> | 2024-11-26 09:28:28 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-11-26 12:25:58 +0100 |
commit | a1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch) | |
tree | 2a24507c67aa99a15416707b2f7e645142230ed8 /server/model/group.js | |
parent | Initial commit. (diff) | |
download | uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.tar.xz uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.zip |
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'server/model/group.js')
-rw-r--r-- | server/model/group.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/server/model/group.js b/server/model/group.js new file mode 100644 index 0000000..bd2c301 --- /dev/null +++ b/server/model/group.js @@ -0,0 +1,46 @@ +const { BeanModel } = require("redbean-node/dist/bean-model"); +const { R } = require("redbean-node"); + +class Group extends BeanModel { + + /** + * Return an object that ready to parse to JSON for public Only show + * necessary data to public + * @param {boolean} showTags Should the JSON include monitor tags + * @param {boolean} certExpiry Should JSON include info about + * certificate expiry? + * @returns {Promise<object>} Object ready to parse + */ + async toPublicJSON(showTags = false, certExpiry = false) { + let monitorBeanList = await this.getMonitorList(); + let monitorList = []; + + for (let bean of monitorBeanList) { + monitorList.push(await bean.toPublicJSON(showTags, certExpiry)); + } + + return { + id: this.id, + name: this.name, + weight: this.weight, + monitorList, + }; + } + + /** + * Get all monitors + * @returns {Promise<Bean[]>} List of monitors + */ + async getMonitorList() { + return R.convertToBeans("monitor", await R.getAll(` + SELECT monitor.*, monitor_group.send_url FROM monitor, monitor_group + WHERE monitor.id = monitor_group.monitor_id + AND group_id = ? + ORDER BY monitor_group.weight + `, [ + this.id, + ])); + } +} + +module.exports = Group; |