[Status Page] Simplify show tags logic

This commit is contained in:
Louis Lam 2022-03-18 17:56:46 +08:00
parent 37be7df9b0
commit aef0a66205
5 changed files with 36 additions and 63 deletions

View file

@ -113,30 +113,14 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
// Public Group List
const publicGroupList = [];
const tagsVisible = !!statusPage.show_tags;
const showTags = !!statusPage.show_tags;
debug("Show Tags???" + showTags);
const list = await R.find("group", " public = 1 AND status_page_id = ? ORDER BY weight ", [
statusPage.id
]);
for (let groupBean of list) {
let monitorGroup = await groupBean.toPublicJSON();
if (tagsVisible) {
monitorGroup.monitorList = await Promise.all(monitorGroup.monitorList.map(async (monitor) => {
// Includes tags as an array in response, allows for tags to be displayed on public status page
const tags = await R.getAll(
`SELECT monitor_tag.monitor_id, monitor_tag.value, tag.name, tag.color
FROM monitor_tag
JOIN tag
ON monitor_tag.tag_id = tag.id
WHERE monitor_tag.monitor_id = ?`, [monitor.id]
);
return {
...monitor,
tags: tags
};
}));
}
let monitorGroup = await groupBean.toPublicJSON(showTags);
publicGroupList.push(monitorGroup);
}