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.
78 lines
1.3 KiB
JavaScript
78 lines
1.3 KiB
JavaScript
import mongoose from "mongoose";
|
|
const { ObjectId } = mongoose.Schema;
|
|
|
|
const reviewSchema = mongoose.Schema(
|
|
{
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
rating: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
comment: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
user: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
required: true,
|
|
ref: "User",
|
|
},
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
const productSchema = mongoose.Schema(
|
|
{
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
image: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
brand: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
quantity: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
category: {
|
|
type: ObjectId,
|
|
ref: "Category",
|
|
required: true,
|
|
},
|
|
description: { type: String, required: true },
|
|
reviews: [reviewSchema],
|
|
rating: {
|
|
type: Number,
|
|
required: true,
|
|
default: 0,
|
|
},
|
|
numReviews: {
|
|
type: Number,
|
|
required: true,
|
|
default: 0,
|
|
},
|
|
price: {
|
|
type: Number,
|
|
required: true,
|
|
default: 0,
|
|
},
|
|
countInStock: {
|
|
type: Number,
|
|
required: true,
|
|
default: 0,
|
|
},
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
const Product = mongoose.model("Product", productSchema);
|
|
export default Product;
|