-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,71 @@ | ||
import mongoose from "mongoose"; | ||
import EmailService from "../../service/emailService.js"; | ||
import Notification from "./Notification.js"; | ||
|
||
const BaseCheckSchema = mongoose.Schema({ | ||
/** | ||
* Reference to the associated Monitor document. | ||
* | ||
* @type {mongoose.Schema.Types.ObjectId} | ||
*/ | ||
monitorId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "Monitor", | ||
immutable: true, | ||
index: true, | ||
}, | ||
/** | ||
* Status of the check (true for up, false for down). | ||
* | ||
* @type {Boolean} | ||
*/ | ||
status: { | ||
type: Boolean, | ||
index: true, | ||
}, | ||
/** | ||
* Response time of the check in milliseconds. | ||
* | ||
* @type {Number} | ||
*/ | ||
responseTime: { | ||
type: Number, | ||
}, | ||
/** | ||
* HTTP status code received during the check. | ||
* | ||
* @type {Number} | ||
*/ | ||
statusCode: { | ||
type: Number, | ||
index: true, | ||
}, | ||
/** | ||
* Message or description of the check result. | ||
* | ||
* @type {String} | ||
*/ | ||
message: { | ||
type: String, | ||
}, | ||
/** | ||
* Expiry date of the check, auto-calculated to expire after 30 days. | ||
* | ||
* @type {Date} | ||
*/ | ||
|
||
expiry: { | ||
type: Date, | ||
default: Date.now, | ||
expires: 60 * 60 * 24 * 30, // 30 days | ||
}, | ||
}); | ||
|
||
/** | ||
* 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( | ||
{ | ||
/** | ||
* Reference to the associated Monitor document. | ||
* | ||
* @type {mongoose.Schema.Types.ObjectId} | ||
*/ | ||
monitorId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "Monitor", | ||
immutable: true, | ||
index: true, | ||
}, | ||
/** | ||
* Status of the check (true for up, false for down). | ||
* | ||
* @type {Boolean} | ||
*/ | ||
status: { | ||
type: Boolean, | ||
index: true, | ||
}, | ||
/** | ||
* Response time of the check in milliseconds. | ||
* | ||
* @type {Number} | ||
*/ | ||
responseTime: { | ||
type: Number, | ||
}, | ||
/** | ||
* HTTP status code received during the check. | ||
* | ||
* @type {Number} | ||
*/ | ||
statusCode: { | ||
type: Number, | ||
index: true, | ||
}, | ||
/** | ||
* Message or description of the check result. | ||
* | ||
* @type {String} | ||
*/ | ||
message: { | ||
type: String, | ||
}, | ||
/** | ||
* Expiry date of the check, auto-calculated to expire after 30 days. | ||
* | ||
* @type {Date} | ||
*/ | ||
|
||
expiry: { | ||
type: Date, | ||
default: Date.now, | ||
expires: 60 * 60 * 24 * 30, // 30 days | ||
}, | ||
}, | ||
{ | ||
timestamps: true, // Adds createdAt and updatedAt timestamps | ||
} | ||
); | ||
|
||
const CheckSchema = mongoose.Schema({ ...BaseCheckSchema.obj }, { timestamps: true }); | ||
CheckSchema.index({ createdAt: 1 }); | ||
export default mongoose.model("Check", CheckSchema); | ||
export { BaseCheckSchema }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters