const mongoose = require("mongoose") const productSchema = new mongoose.Schema({ productId: { type: mongoose.Schema.Types.ObjectId, ref: "Product", required: true, }, productName: { type: String, required: true }, quantity: { type: Number, required: true }, }) const userSchema = new mongoose.Schema({ email: { type: String, required: true, unique: true }, firstName: { type: String }, lastName: { type: String }, password: { type: String, required: true }, isAdmin: { type: Boolean, default: false }, orderedProducts: [ { products: [productSchema], totalAmount: { type: Number, required: true }, purchaseOn: { type: Date, default: Date.now }, }, ], }) const User = mongoose.model("User", userSchema) module.exports = User