Files
Checkmate/Server/models/Check.js
T

77 lines
1.6 KiB
JavaScript
Raw Normal View History

const mongoose = require("mongoose");
const EmailService = require("../service/emailService");
2024-08-06 20:45:27 -07:00
const Notification = require("../models/Notification");
2024-08-06 19:36:43 -07:00
/**
* Check Schema for MongoDB collection.
*
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.
*/
const CheckSchema = mongoose.Schema(
{
2024-08-06 19:36:43 -07:00
/**
* Reference to the associated Monitor document.
*
2024-08-06 19:36:43 -07:00
* @type {mongoose.Schema.Types.ObjectId}
*/
monitorId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Monitor",
immutable: true,
2024-09-17 09:16:00 +08:00
index: true,
},
2024-08-06 19:36:43 -07:00
/**
* Status of the check (true for up, false for down).
*
2024-08-06 19:36:43 -07:00
* @type {Boolean}
*/
status: {
type: Boolean,
2024-09-17 09:16:00 +08:00
index: true,
},
2024-08-06 19:36:43 -07:00
/**
* Response time of the check in milliseconds.
*
2024-08-06 19:36:43 -07:00
* @type {Number}
*/
responseTime: {
type: Number,
},
2024-08-06 19:36:43 -07:00
/**
* HTTP status code received during the check.
*
2024-08-06 19:36:43 -07:00
* @type {Number}
*/
statusCode: {
type: Number,
2024-09-17 09:16:00 +08:00
index: true,
},
2024-08-06 19:36:43 -07:00
/**
* Message or description of the check result.
*
2024-08-06 19:36:43 -07:00
* @type {String}
*/
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-06 19:36:43 -07:00
* @type {Date}
*/
2024-08-12 15:15:13 -07:00
expiry: {
type: Date,
default: Date.now,
2024-08-06 19:36:43 -07:00
expires: 60 * 60 * 24 * 30, // 30 days
},
},
{
2024-08-06 19:36:43 -07:00
timestamps: true, // Adds createdAt and updatedAt timestamps
}
);
2024-09-17 09:16:00 +08:00
CheckSchema.index({ createdAt: 1 });
module.exports = mongoose.model("Check", CheckSchema);