first commit
This commit is contained in:
53
mongodb/models/index.ts
Normal file
53
mongodb/models/index.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import mongoose, {Schema} from "mongoose";
|
||||
|
||||
// API Request Logs
|
||||
const ApiRequestLogSchema = new Schema({
|
||||
method: {type: String, required: true},
|
||||
path: {type: String, required: true},
|
||||
status: {type: Number, required: true},
|
||||
durationMs: {type: Number, required: true},
|
||||
userId: {type: String, required: false},
|
||||
role: {type: String},
|
||||
createdAt: {type: Date, default: Date.now},
|
||||
});
|
||||
|
||||
export const ApiRequestLog = mongoose.model(
|
||||
"ApiRequestLog",
|
||||
ApiRequestLogSchema
|
||||
);
|
||||
|
||||
// Error Logs
|
||||
const ErrorLogSchema = new Schema({
|
||||
message: {type: String, required: true},
|
||||
stack: {type: String},
|
||||
severity: {type: String, default: "error"},
|
||||
createdAt: {type: Date, default: Date.now},
|
||||
});
|
||||
|
||||
export const ErrorLog = mongoose.model("ErrorLog", ErrorLogSchema);
|
||||
|
||||
// Security Event Logs
|
||||
const SecurityEventSchema = new Schema({
|
||||
type: {type: String, required: true},
|
||||
userId: {type: String},
|
||||
ip: {type: String},
|
||||
createdAt: {type: Date, default: Date.now},
|
||||
});
|
||||
|
||||
export const SecurityEventLog = mongoose.model(
|
||||
"SecurityEventLog",
|
||||
SecurityEventSchema
|
||||
);
|
||||
|
||||
// Performance Logs
|
||||
const PerformanceLogSchema = new Schema({
|
||||
metric: {type: String, required: true},
|
||||
valueMs: {type: Number, required: true},
|
||||
endpoint: {type: String},
|
||||
createdAt: {type: Date, default: Date.now},
|
||||
});
|
||||
|
||||
export const PerformanceLog = mongoose.model(
|
||||
"PerformanceLog",
|
||||
PerformanceLogSchema
|
||||
);
|
||||
Reference in New Issue
Block a user