2021-09-19 13:04:51 +02:00
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
|
|
|
|
class Group extends BeanModel {
|
|
|
|
|
|
|
|
async toPublicJSON() {
|
2021-09-19 17:24:51 +02:00
|
|
|
let monitorBeanList = await this.getMonitorList();
|
2021-09-19 13:04:51 +02:00
|
|
|
let monitorList = [];
|
|
|
|
|
|
|
|
for (let bean of monitorBeanList) {
|
|
|
|
monitorList.push(await bean.toPublicJSON());
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
name: this.name,
|
|
|
|
weight: this.weight,
|
|
|
|
monitorList,
|
|
|
|
};
|
|
|
|
}
|
2021-09-19 17:24:51 +02:00
|
|
|
|
|
|
|
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 = ?
|
2021-09-22 09:23:58 +02:00
|
|
|
ORDER BY monitor_group.weight
|
2021-09-19 17:24:51 +02:00
|
|
|
`, [
|
|
|
|
this.id,
|
|
|
|
]));
|
|
|
|
}
|
2021-09-19 13:04:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Group;
|