diff --git a/lib/models/product.model.ts b/lib/models/product.model.ts new file mode 100644 index 0000000..0cf28c8 --- /dev/null +++ b/lib/models/product.model.ts @@ -0,0 +1,31 @@ +import mongoose from 'mongoose'; + +const productSchema = new mongoose.Schema({ + url: {type: String, required: true, unique: true}, + currency: {type: String, required: true}, + image: { type: String, required: true}, + title: { type: String, required: true}, + currentPrice: { type: Number, required: true}, + originalPrice: { type: Number, required: true}, + priceHistory: [ + { + price: {type: Number, required: true}, + date: {type: Date, default: Date.now} + } + ], + lowestPrice: {type: Number}, + highestPrice: {type: Number}, + averagePrice: {type: Number}, + discountRate: {type: Number}, + description: {type: String}, + category: {type: String}, + reviewCount: {type: Number}, + isOutOfStock: {type: Boolean, default: false}, + users: [ + {email: {type: String, required: true}} + ], default: [], +}, {timestamps: true}); + +const Product = mongoose.models.Product || mongoose.model('Product', productSchema); + +export default Product; \ No newline at end of file