Monitor now has a status, status will be updated on new check

This commit is contained in:
Alex Holliday committed 2024-07-03 11:41:12 -07:00
1 parent 3a1bd48d89
commit 9ccf42fe55
2 files changed
+21

No files matched your search

+17
View File
@@ -31,4 +31,21 @@ const CheckSchema = mongoose.Schema(
}
);
CheckSchema.pre("save", async function (next) {
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
if (monitor.status === true && this.status === false) {
console.log("Monitor went down");
}
if (monitor.status === false && this.status === true) {
console.log("Monitor went up");
}
monitor.status = this.status;
await monitor.save();
next;
});
module.exports = mongoose.model("Check", CheckSchema);
+4
View File
@@ -14,6 +14,10 @@ const MonitorSchema = mongoose.Schema(
description: {
type: String,
},
status: {
type: Boolean,
default: true,
},
type: {
type: String,
required: true,