-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathOrder.js
34 lines (31 loc) · 973 Bytes
/
Order.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
const mongoose = require('mongoose');
const { Schema } = mongoose;
const paymentMethods = {
values: ['card', 'cash'],
message: 'enum validator failed for payment Methods'
}
const orderSchema = new Schema(
{
items: { type: [Schema.Types.Mixed], required: true },
totalAmount: { type: Number },
totalItems: { type: Number },
user: { type: Schema.Types.ObjectId, ref: 'User', required: true },
paymentMethod: { type: String, required: true, enum: paymentMethods },
paymentStatus: { type: String, default: 'pending' },
status: { type: String, default: 'pending' },
selectedAddress: { type: Schema.Types.Mixed, required: true },
},
{ timestamps: true }
);
const virtual = orderSchema.virtual('id');
virtual.get(function () {
return this._id;
});
orderSchema.set('toJSON', {
virtuals: true,
versionKey: false,
transform: function (doc, ret) {
delete ret._id;
},
});
exports.Order = mongoose.model('Order', orderSchema);