24 lines
658 B
JavaScript
24 lines
658 B
JavaScript
import mongoose from "mongoose";
|
|
const { Schema } = mongoose;
|
|
|
|
// Define the main partStock schema
|
|
const partStockSchema = new Schema(
|
|
{
|
|
name: { type: String, required: true },
|
|
fileName: { type: String, required: false },
|
|
product: { type: mongoose.Schema.Types.ObjectId, ref: "Product" },
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
// Add virtual id getter
|
|
partStockSchema.virtual("id").get(function () {
|
|
return this._id.toHexString();
|
|
});
|
|
|
|
// Configure JSON serialization to include virtuals
|
|
partStockSchema.set("toJSON", { virtuals: true });
|
|
|
|
// Create and export the model
|
|
export const partStockModel = mongoose.model("PartStock", partStockSchema);
|