Add docs.
This commit is contained in:
1 parent
67711ffe2c
commit
7b2311d468
1 file changed
+44
-4
+44
-4
@@ -1,36 +1,78 @@
|
|||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const EmailService = require("../service/emailService");
|
const EmailService = require("../service/emailService");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check Schema for MongoDB collection.
|
||||||
|
*
|
||||||
|
* Represents a check associated with a monitor, storing information
|
||||||
|
* about the status and response of a particular check event.
|
||||||
|
*/
|
||||||
const CheckSchema = mongoose.Schema(
|
const CheckSchema = mongoose.Schema(
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Reference to the associated Monitor document.
|
||||||
|
*
|
||||||
|
* @type {mongoose.Schema.Types.ObjectId}
|
||||||
|
*/
|
||||||
monitorId: {
|
monitorId: {
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
ref: "Monitor",
|
ref: "Monitor",
|
||||||
immutable: true,
|
immutable: true,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Status of the check (true for up, false for down).
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
status: {
|
status: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Response time of the check in milliseconds.
|
||||||
|
*
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
responseTime: {
|
responseTime: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* HTTP status code received during the check.
|
||||||
|
*
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
statusCode: {
|
statusCode: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Message or description of the check result.
|
||||||
|
*
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
message: {
|
message: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Expiry date of the check, auto-calculated to expire after 30 days.
|
||||||
|
*
|
||||||
|
* @type {Date}
|
||||||
|
*/
|
||||||
expiry: {
|
expiry: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
default: Date.now,
|
||||||
expires: 60 * 60 * 24 * 30,
|
expires: 60 * 60 * 24 * 30, // 30 days
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timestamps: true,
|
timestamps: true, // Adds createdAt and updatedAt timestamps
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-save middleware to handle status change notifications.
|
||||||
|
*
|
||||||
|
* This middleware checks if the status of the monitor associated
|
||||||
|
* with the check has changed and sends notifications if necessary.
|
||||||
|
*/
|
||||||
CheckSchema.pre("save", async function (next) {
|
CheckSchema.pre("save", async function (next) {
|
||||||
try {
|
try {
|
||||||
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
|
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
|
||||||
@@ -83,6 +125,4 @@ CheckSchema.pre("save", async function (next) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = mongoose.model("Check", CheckSchema);
|
module.exports = mongoose.model("Check", CheckSchema);
|
||||||
Reference in new issue
Block a user