Skip to content

Instantly share code, notes, and snippets.

@DulalSandip
Created April 13, 2021 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DulalSandip/30fe644c5f3c832ec3c7d1707a43a713 to your computer and use it in GitHub Desktop.
Save DulalSandip/30fe644c5f3c832ec3c7d1707a43a713 to your computer and use it in GitHub Desktop.
Product Models
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