const mongoose = require("mongoose");
const ItemSchema = new mongoose.Schema(
{
nombre: String,
categoria: {
type: mongoose.Schema.Types.ObjectId,
ref: "Categoria",
},
cantidad: Number,
precio: Number,
},
{
timestamps: true,
versionKey: false,
}
);
const createItemModel = (connection = null) => {
if (connection) {
return connection.model("Item", ItemSchema);
}
return mongoose.model("Item", ItemSchema);
};
module.exports = createItemModel();
module.exports.createItemModel = createItemModel;
module.exports.ItemSchema = ItemSchema;