-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from deenuy/Paulo-01-Models
Creating models
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Main model of the project, which is responsible for holding the orders made through the app. | ||
// This collection will relate to Users collection and Products collection. | ||
import mongoose from 'mongoose'; | ||
const orderSchema = new mongoose.Schema( | ||
{ | ||
orderItems: [ | ||
{ | ||
name: { type: String, required: true }, | ||
qty: { type: Number, required: true }, | ||
image: { type: String, required: true }, | ||
price: { type: Number, required: true }, | ||
product: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Product', | ||
required: true, | ||
}, | ||
}, | ||
], | ||
shippingAddress: { | ||
fullName: { type: String, required: true }, | ||
address: { type: String, required: true }, | ||
city: { type: String, required: true }, | ||
postalCode: { type: String, required: true }, | ||
country: { type: String, required: true }, | ||
}, | ||
paymentMethod: { type: String, required: true }, | ||
paymentResult: { | ||
id: String, | ||
status: String, | ||
update_time: String, | ||
email_address: String, | ||
}, | ||
itemsPrice: { type: Number, required: true }, | ||
shippingPrice: { type: Number, required: true }, | ||
taxPrice: { type: Number, required: true }, | ||
totalPrice: { type: Number, required: true }, | ||
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, | ||
isPaid: { type: Boolean, default: false }, | ||
paidAt: { type: Date }, | ||
isDelivered: { type: Boolean, default: false }, | ||
deliveredAt: { type: Date }, | ||
}, | ||
{ | ||
timestamps: true, | ||
} | ||
); | ||
const Order = mongoose.model('Order', orderSchema); | ||
export default Order; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Product Model holds all the products available in the virtual pet store. | ||
// Admin users will be able to do all the CRUD operations on this model. | ||
// Ordinary users (Buyers) can only read it. | ||
import mongoose from 'mongoose'; | ||
const productSchema = new mongoose.Schema( | ||
{ | ||
name: { type: String, required: true, unique: true }, | ||
image: { type: String, required: true }, | ||
brand: { type: String, required: true }, | ||
category: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
price: { type: Number, required: true }, | ||
countInStock: { type: Number, required: true }, | ||
rating: { type: Number, required: true }, | ||
numReviews: { type: Number, required: true }, | ||
}, | ||
{ | ||
timestamps: true, | ||
} | ||
); | ||
const Product = mongoose.model('Product', productSchema); | ||
|
||
export default Product; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// User models holds all the users authorized to use the app. | ||
// User password will be safely saved in the database using cryptography | ||
import mongoose from 'mongoose'; | ||
const userSchema = new mongoose.Schema( | ||
{ | ||
name: { type: String, required: true }, | ||
email: { type: String, required: true, unique: true }, | ||
password: { type: String, required: true }, | ||
isAdmin: { type: Boolean, default: false, required: true }, | ||
}, | ||
{ | ||
timestamps: true, | ||
} | ||
); | ||
const User = mongoose.model('User', userSchema); | ||
export default User; |