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.

31 lines
757 B
JavaScript

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