Files
2026-03-26 08:14:56 +03:30

54 lines
1.4 KiB
TypeScript

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
);