Monitor now has a status, status will be updated on new check
This commit is contained in:
1 parent
3a1bd48d89
commit
9ccf42fe55
2 files changed
+21
No files matched your search
@@ -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);
|
||||
@@ -14,6 +14,10 @@ const MonitorSchema = mongoose.Schema(
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
status: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
|
||||
Reference in new issue
Block a user