Browse Source

fix(monitor-checks): use helper for saving monitor checks

bertyhell/feature/monitor-checks
Bert Verhelst 3 years ago
parent
commit
1a7b69d4aa
  1. 21
      server/server.js

21
server/server.js

@ -536,26 +536,7 @@ exports.entryPage = "dashboard";
await R.store(bean); await R.store(bean);
// Store checks await updateMonitorChecks(bean.id, checks);
let trx = await R.begin();
try {
// delete existing checks for monitor
await trx.exec("DELETE FROM `monitor_checks` WHERE monitor_id = ?", [bean.id]);
// Replace them with new checks
for (let i = 0; i < (checks || []).length; i++) {
let checkBean = trx.dispense("monitor_checks");
checkBean.type = checks[i].type;
checkBean.value = typeof checks[i].value === "object" ? JSON.stringify(checks[i].value) : checks[i].value;
checkBean.monitor_id = bean.id;
await trx.store(checkBean);
}
await trx.commit();
} catch (err) {
await trx.rollback();
throw err;
}
await updateMonitorNotification(bean.id, monitor.notificationIDList); await updateMonitorNotification(bean.id, monitor.notificationIDList);
if (bean.active) { if (bean.active) {

Loading…
Cancel
Save