27 lines
583 B
JavaScript
27 lines
583 B
JavaScript
import mongoose from 'mongoose';
|
|
|
|
// Define Product record schema
|
|
const ProductRecordSchema = new mongoose.Schema({
|
|
productid: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Product',
|
|
required: true,
|
|
},
|
|
Stock: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
});
|
|
|
|
// Define main Stock schema
|
|
const StockSchema = new mongoose.Schema({
|
|
userId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'User',
|
|
required: true,
|
|
},
|
|
products: [ProductRecordSchema],
|
|
}, { timestamps: true, versionKey: false });
|
|
|
|
export const PDStock = mongoose.model('PDStock', StockSchema);
|