Added error checking and fixed typo
This commit is contained in:
1 parent
031ae06d41
commit
505d9f2890
1 file changed
+16
-12
+16
-12
@@ -37,21 +37,25 @@ const CheckSchema = mongoose.Schema(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CheckSchema.pre("save", async function (next) {
|
CheckSchema.pre("save", async function (next) {
|
||||||
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
|
try {
|
||||||
if (monitor.status !== this.status) {
|
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
|
||||||
if (monitor.status === true && this.status === false) {
|
if (monitor && monitor.status !== this.status) {
|
||||||
// TODO issue alert
|
if (monitor.status === true && this.status === false) {
|
||||||
console.log("Monitor went down");
|
// TODO issue alert
|
||||||
}
|
console.log("Monitor went down");
|
||||||
|
}
|
||||||
|
|
||||||
if (monitor.status === false && this.status === true) {
|
if (monitor.status === false && this.status === true) {
|
||||||
// TODO issue alert
|
// TODO issue alert
|
||||||
console.log("Monitor went up");
|
console.log("Monitor went up");
|
||||||
|
}
|
||||||
|
await monitor.save();
|
||||||
}
|
}
|
||||||
await monitor.save();
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
next;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = mongoose.model("Check", CheckSchema);
|
module.exports = mongoose.model("Check", CheckSchema);
|
||||||
Reference in new issue
Block a user