41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import mongoose from "mongoose";
|
|
const { Schema } = mongoose;
|
|
|
|
const auditLogSchema = new Schema(
|
|
{
|
|
oldValue: { type: Object, required: true },
|
|
newValue: { type: Object, required: true },
|
|
target: {
|
|
type: Schema.Types.ObjectId,
|
|
refPath: 'targetModel',
|
|
required: true
|
|
},
|
|
targetModel: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['Printer', 'Job', 'SubJob', 'FilamentStock', 'StockEvent', 'Vendor', 'Part', 'Product', 'Material', 'Filament', 'GCodeFile', 'NoteType', 'Note', 'User'] // Add other models as needed
|
|
},
|
|
owner: {
|
|
type: Schema.Types.ObjectId,
|
|
refPath: 'ownerModel',
|
|
required: true
|
|
},
|
|
ownerModel: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['User', 'Printer']
|
|
}
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
// Add virtual id getter
|
|
auditLogSchema.virtual("id").get(function () {
|
|
return this._id.toHexString();
|
|
});
|
|
|
|
// Configure JSON serialization to include virtuals
|
|
auditLogSchema.set("toJSON", { virtuals: true });
|
|
|
|
// Create and export the model
|
|
export const auditLogModel = mongoose.model("AuditLog", auditLogSchema);
|