2021-09-19 19:04:51 +08:00
|
|
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
|
|
|
const { R } = require("redbean-node");
|
|
|
|
|
|
|
|
|
|
class Group extends BeanModel {
|
2022-04-16 21:11:45 +01:00
|
|
|
/**
|
2023-08-11 09:46:41 +02:00
|
|
|
* 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?
|
2024-03-15 15:02:55 +01:00
|
|
|
* @returns {Promise<object>} Object ready to parse
|
2022-04-16 21:11:45 +01:00
|
|
|
*/
|
2023-07-04 19:37:45 -04:00
|
|
|
async toPublicJSON(showTags = false, certExpiry = false) {
|
2021-09-19 23:24:51 +08:00
|
|
|
let monitorBeanList = await this.getMonitorList();
|
2021-09-19 19:04:51 +08:00
|
|
|
let monitorList = [];
|
|
|
|
|
|
|
|
|
|
for (let bean of monitorBeanList) {
|
2023-07-04 19:37:45 -04:00
|
|
|
monitorList.push(await bean.toPublicJSON(showTags, certExpiry));
|
2021-09-19 19:04:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: this.id,
|
|
|
|
|
name: this.name,
|
|
|
|
|
weight: this.weight,
|
|
|
|
|
monitorList,
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-19 23:24:51 +08:00
|
|
|
|
2022-04-16 21:11:45 +01:00
|
|
|
/**
|
|
|
|
|
* Get all monitors
|
2024-03-15 15:02:55 +01:00
|
|
|
* @returns {Promise<Bean[]>} List of monitors
|
2022-04-16 21:11:45 +01:00
|
|
|
*/
|
2021-09-19 23:24:51 +08:00
|
|
|
async getMonitorList() {
|
2026-01-09 02:10:36 +01:00
|
|
|
return R.convertToBeans(
|
|
|
|
|
"monitor",
|
|
|
|
|
await R.getAll(
|
|
|
|
|
`
|
2025-05-10 19:05:37 +02:00
|
|
|
SELECT monitor.*, monitor_group.send_url, monitor_group.custom_url FROM monitor, monitor_group
|
2021-09-19 23:24:51 +08:00
|
|
|
WHERE monitor.id = monitor_group.monitor_id
|
|
|
|
|
AND group_id = ?
|
2021-09-22 15:23:58 +08:00
|
|
|
ORDER BY monitor_group.weight
|
2026-01-09 02:10:36 +01:00
|
|
|
`,
|
|
|
|
|
[this.id]
|
|
|
|
|
)
|
|
|
|
|
);
|
2021-09-19 23:24:51 +08:00
|
|
|
}
|
2021-09-19 19:04:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = Group;
|