You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
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=false] Should the JSON include monitor tags
|
|
* @returns {Object}
|
|
*/
|
|
async toPublicJSON(showTags = false, showStatus = false) {
|
|
let monitorBeanList = await this.getMonitorList();
|
|
let monitorList = [];
|
|
|
|
for (let bean of monitorBeanList) {
|
|
monitorList.push(await bean.toPublicJSON(showTags, showStatus));
|
|
}
|
|
|
|
return {
|
|
id: this.id,
|
|
name: this.name,
|
|
weight: this.weight,
|
|
monitorList,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get all monitors
|
|
* @returns {Bean[]}
|
|
*/
|
|
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;
|