2024-06-18 12:45:25 -07:00
|
|
|
const mongoose = require("mongoose");
|
2024-08-01 20:42:14 -07:00
|
|
|
const EmailService = require("../service/emailService");
|
2024-08-06 20:45:27 -07:00
|
|
|
const Notification = require("../models/Notification");
|
2024-05-27 15:07:34 -04:00
|
|
|
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* Check Schema for MongoDB collection.
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* Represents a check associated with a monitor, storing information
|
|
|
|
|
* about the status and response of a particular check event.
|
|
|
|
|
*/
|
2024-05-27 15:07:34 -04:00
|
|
|
const CheckSchema = mongoose.Schema(
|
2024-06-18 12:45:25 -07:00
|
|
|
{
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* Reference to the associated Monitor document.
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* @type {mongoose.Schema.Types.ObjectId}
|
|
|
|
|
*/
|
2024-06-18 12:45:25 -07:00
|
|
|
monitorId: {
|
|
|
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
|
|
|
ref: "Monitor",
|
|
|
|
|
immutable: true,
|
2024-05-27 15:07:34 -04:00
|
|
|
},
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* Status of the check (true for up, false for down).
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* @type {Boolean}
|
|
|
|
|
*/
|
2024-06-18 12:45:25 -07:00
|
|
|
status: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* Response time of the check in milliseconds.
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* @type {Number}
|
|
|
|
|
*/
|
2024-06-18 12:45:25 -07:00
|
|
|
responseTime: {
|
2024-08-09 11:54:30 -07:00
|
|
|
type: Number,
|
2024-06-18 12:45:25 -07:00
|
|
|
},
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* HTTP status code received during the check.
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* @type {Number}
|
|
|
|
|
*/
|
2024-06-18 12:45:25 -07:00
|
|
|
statusCode: {
|
2024-08-09 11:54:30 -07:00
|
|
|
type: Number,
|
2024-06-18 12:45:25 -07:00
|
|
|
},
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* Message or description of the check result.
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* @type {String}
|
|
|
|
|
*/
|
2024-06-18 12:45:25 -07:00
|
|
|
message: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2024-08-06 19:36:43 -07:00
|
|
|
/**
|
|
|
|
|
* Expiry date of the check, auto-calculated to expire after 30 days.
|
2024-08-09 11:54:30 -07:00
|
|
|
*
|
2024-08-06 19:36:43 -07:00
|
|
|
* @type {Date}
|
|
|
|
|
*/
|
2024-08-12 15:15:13 -07:00
|
|
|
|
2024-06-18 12:45:25 -07:00
|
|
|
expiry: {
|
|
|
|
|
type: Date,
|
|
|
|
|
default: Date.now,
|
2024-08-06 19:36:43 -07:00
|
|
|
expires: 60 * 60 * 24 * 30, // 30 days
|
2024-06-18 12:45:25 -07:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-08-06 19:36:43 -07:00
|
|
|
timestamps: true, // Adds createdAt and updatedAt timestamps
|
2024-06-18 12:45:25 -07:00
|
|
|
}
|
2024-05-27 15:07:34 -04:00
|
|
|
);
|
|
|
|
|
|
2024-06-18 12:45:25 -07:00
|
|
|
module.exports = mongoose.model("Check", CheckSchema);
|