[status page] many update and save group list

This commit is contained in:
LouisLam
2021-09-19 19:04:51 +08:00
parent 6681f49a58
commit fd95d41d9f
16 changed files with 288 additions and 127 deletions

33
server/model/group.js Normal file
View File

@@ -0,0 +1,33 @@
const { BeanModel } = require("redbean-node/dist/bean-model");
const { R } = require("redbean-node");
class Group extends BeanModel {
async toPublicJSON() {
let monitorBeanList = R.convertToBeans("monitor", await R.getAll(`
SELECT * FROM monitor, monitor_group
WHERE monitor.id = monitor_group.monitor_id
AND group_id = ?
`, [
this.id,
]));
console.log(monitorBeanList);
let monitorList = [];
for (let bean of monitorBeanList) {
monitorList.push(await bean.toPublicJSON());
}
return {
id: this.id,
name: this.name,
weight: this.weight,
monitorList,
};
}
}
module.exports = Group;

View File

@@ -10,6 +10,7 @@ class Incident extends BeanModel {
content: this.content,
pin: this.pin,
createdDate: this.createdDate,
lastUpdatedDate: this.lastUpdatedDate,
};
}
}

View File

@@ -26,8 +26,10 @@ class Monitor extends BeanModel {
* Only show necessary data to public
*/
async toPublicJSON() {
// TODO Only show necessary
return this.toJSON();
return {
id: this.id,
name: this.name,
};
}
/**