aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-27 17:18:41 +0200
committerMateja <mail@matejamaric.com>2021-07-27 17:18:41 +0200
commit8a3923c5b9eefaaa59a081c2a77d0a225494ea45 (patch)
treef359a1f6c8551afdc2b7ff9f9ebe4fdc0f8877c8 /server
parent021638d3c21f42b0f315333f64c3c2ca8966e2cc (diff)
downloadmevn-ecommerce-8a3923c5b9eefaaa59a081c2a77d0a225494ea45.tar.gz
mevn-ecommerce-8a3923c5b9eefaaa59a081c2a77d0a225494ea45.zip
Improve `Order` model.
Added timestamps and now using `ItemSchema` as subschema for array of items.
Diffstat (limited to 'server')
-rw-r--r--server/models/Order.js28
1 files changed, 17 insertions, 11 deletions
diff --git a/server/models/Order.js b/server/models/Order.js
index 9615373..a4b2508 100644
--- a/server/models/Order.js
+++ b/server/models/Order.js
@@ -1,5 +1,20 @@
const mongoose = require('mongoose');
+const ItemSchema = new mongoose.Schema({
+ productId: {
+ type: mongoose.Schema.Types.ObjectId,
+ required: true
+ },
+ name: {
+ type: String,
+ required: false
+ },
+ quantity: {
+ type: Number,
+ required: true
+ }
+}, {_id: false});
+
const OrderSchema = new mongoose.Schema({
status: {
type: String,
@@ -14,16 +29,7 @@ const OrderSchema = new mongoose.Schema({
required: false
},
items: {
- type: [{
- productId: {
- type: mongoose.Schema.Types.ObjectId,
- required: true
- },
- quantity: {
- type: Number,
- required: true
- }
- }],
+ type: [ItemSchema],
required: true
},
shipping: {
@@ -43,7 +49,7 @@ const OrderSchema = new mongoose.Schema({
},
required: false
}
-});
+}, {timestamps: true});
const OrderModel = new mongoose.model('Order', OrderSchema);