/
models.js
93 lines (83 loc) · 1.79 KB
/
models.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
const mongoose = require('mongoose');
const productSchema = new mongoose.Schema({
productName: String,
productPrice: Number
});
const Product = mongoose.model('Product', productSchema);
module.exports.Product = Product;
const orderSchema = new mongoose.Schema({
items: [{ productId: { type: mongoose.ObjectId, required: true, ref: 'Product' }, quantity: { type: Number, required: true } }],
total: {
type: Number,
default: 0
},
status: {
type: String,
enum: ['PAID', 'IN_PROGRESS', 'SHIPPED', 'DELIVERED'],
default: 'PAID'
},
orderNumber: {
type: Number,
required: true
},
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
address1: {
type: String,
required: true
},
address2: {
type: String
},
city: {
type: String,
required: true
},
state: {
type: String,
required: true
},
zip: {
type: String,
required: true
},
location: new mongoose.Schema({
lat: {
type: Number,
required: true
},
lng: {
type: Number,
required: true
}
}, { _id: false }),
shipping: {
type: String,
required: true,
enum: ['standard', '2day']
},
paymentMethod: {
id: String,
brand: String,
last4: String
},
salesTax: {
type: Number,
default: 0
},
}, { optimisticConcurrency: true });
const Order = mongoose.model('Order', orderSchema);
module.exports.Order = Order;
const cartSchema = new mongoose.Schema({
items: [{ productId: { type: mongoose.ObjectId, required: true, ref: 'Product' }, quantity: { type: Number, required: true } }],
orderId: { type: mongoose.ObjectId, ref: 'Order' }
}, { timestamps: true });
const Cart = mongoose.model('Cart', cartSchema);
module.exports.Cart = Cart;