mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-30 18:24:03 +00:00
34 lines
889 B
JavaScript
34 lines
889 B
JavaScript
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
const { R } = require("redbean-node");
|
|
|
|
class Group extends BeanModel {
|
|
|
|
async toPublicJSON(showTags = false) {
|
|
let monitorBeanList = await this.getMonitorList();
|
|
let monitorList = [];
|
|
|
|
for (let bean of monitorBeanList) {
|
|
monitorList.push(await bean.toPublicJSON(showTags));
|
|
}
|
|
|
|
return {
|
|
id: this.id,
|
|
name: this.name,
|
|
weight: this.weight,
|
|
monitorList,
|
|
};
|
|
}
|
|
|
|
async getMonitorList() {
|
|
return R.convertToBeans("monitor", await R.getAll(`
|
|
SELECT monitor.* FROM monitor, monitor_group
|
|
WHERE monitor.id = monitor_group.monitor_id
|
|
AND group_id = ?
|
|
ORDER BY monitor_group.weight
|
|
`, [
|
|
this.id,
|
|
]));
|
|
}
|
|
}
|
|
|
|
module.exports = Group;
|