You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
675 B
JavaScript

11 months ago
const mongoose = require('mongoose');
const cartProductSchema = new mongoose.Schema({
productId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product',
required: true,
},
productName: { type: String, required: true },
quantity: { type: Number, required: true },
price: { type: Number, required: true },
subtotal: { type: Number, required: true },
});
const cartSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true,
},
products: [cartProductSchema],
totalAmount: { type: Number, required: true },
});
const Cart = mongoose.model('Cart', cartSchema);
module.exports = Cart;