Skip to content

Commit

Permalink
created order schema
Browse files Browse the repository at this point in the history
  • Loading branch information
byohannes committed Oct 29, 2020
1 parent b2c2823 commit 7dc4279
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions models/order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const { ObjectId } = mongoose.Schema;

const CartItemSchema = new mongoose.Schema(
{
product: { type: ObjectId, ref: "Product" },
name: String,
price: Number,
count: Number,
},
{ timestamps: true }
);

const CartItem = mongoose.model("CartItem", CartItemSchema);

const OrderSchema = new mongoose.Schema(
{
products: [CartItemSchema],
transaction_id: {},
amount: { type: Number },
address: String,
status: {
type: String,
default: "Not processed",
enum: [
"Not processed",
"Processing",
"Shipped",
"Delivered",
"Cancelled",
], // enum means string objects
},
updated: Date,
user: { type: ObjectId, ref: "User" },
},
{ timestamps: true }
);

const Order = mongoose.model("Order", OrderSchema);

module.exports = { Order, CartItem };

0 comments on commit 7dc4279

Please sign in to comment.