feat: add incident model, module and service with StatusService integration

- Create Incident model with resolution tracking fields
- Implement IncidentModule for data access
- Implement IncidentService with business logic
- Integrate with StatusService to auto-create/resolve incidents on status change
This commit is contained in:
karenvicent committed 2025-11-06 17:06:33 -05:00
1 parent eb70c9f5f0
commit 0c3fdbc539
7 files changed
+748 -4

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
import mongoose from "mongoose";
const IncidentSchema = mongoose.Schema({
monitorId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Monitor",
required: true,
immutable: true,
index: true
},
teamId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Team",
required: true,
immutable: true,
index: true
},
startTime: {
type: Date,
required: true,
immutable: true
},
endTime: {
type: Date,
default: null
},
status: {
type: String,
enum: ["active", "resolved"],
default: "active",
index: true
},
message: {
type: String,
default: null
},
statusCode: {
type: Number,
index: true,
default: null
},
resolutionType: {
type: String,
enum: ["automatic", "manual"],
default: null
},
resolvedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
default: null
},
comment: {
type: String,
default: null
},
checks: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Check"
}]
}, { timestamps: true });
IncidentSchema.index({ monitorId: 1, status: 1 });
IncidentSchema.index({ teamId: 1, status: 1 });
IncidentSchema.index({ teamId: 1, startTime: -1 });
IncidentSchema.index({ status: 1, startTime: -1 });
IncidentSchema.index({ resolutionType: 1, status: 1 });
IncidentSchema.index({ resolvedBy: 1, status: 1 });
IncidentSchema.index({ createdAt: -1 });
const Incident = mongoose.model("Incident", IncidentSchema);
export default Incident;