Created
April 13, 2021 08:29
-
-
Save DulalSandip/30fe644c5f3c832ec3c7d1707a43a713 to your computer and use it in GitHub Desktop.
Product Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require("mongoose"); | |
const moment = require("moment"); | |
const Schema = mongoose.Schema; | |
const productSchema = new Schema({ | |
name: { | |
type: String, | |
required: true, | |
trim: true, | |
}, | |
slug: { | |
type: String, | |
required: true, | |
unique: true, | |
}, | |
price: { | |
type: String, | |
required: true, | |
}, | |
quantity: { | |
type: Number, | |
required: true, | |
}, | |
description: { | |
type: String, | |
required: true, | |
trim: true, | |
}, | |
discount: { | |
type: Number | |
}, | |
productPictures: [{ | |
img: { | |
type: String, | |
}, | |
}, ], | |
reviews: [{ | |
userId: { | |
type: mongoose.Schema.Types.ObjectId, | |
ref: "user", | |
review: String, | |
}, | |
}, ], | |
rating: [{ | |
userId: { | |
type: mongoose.Schema.Types.ObjectId, | |
ref: "user", | |
review: String, | |
}, | |
}, ], | |
category: { | |
type: mongoose.Schema.Types.ObjectId, | |
ref: "category", | |
required: true, | |
}, | |
createdBy: { | |
type: mongoose.Schema.Types.ObjectId, | |
ref: "admin", | |
required: true, | |
}, | |
createdAt: { | |
type: String, | |
default: moment().format("DD/MM/YYYY") + ";" + moment().format("hh:mm:ss"), | |
}, | |
updatedAt: { | |
type: String, | |
default: moment().format("DD/MM/YYYY") + ";" + moment().format("hh:mm:ss"), | |
}, | |
}); | |
const Product = mongoose.model("product", productSchema); | |
module.exports = Product; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment