-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add filtering orders by current and past - fix userType, productType, orderType to match their models
- Loading branch information
1 parent
3db3257
commit 82a7ea0
Showing
11 changed files
with
99 additions
and
63 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
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
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
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
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 |
---|---|---|
@@ -1,8 +1,23 @@ | ||
import { OrderItemType, OrderStatusType } from '../../types/Order.types'; | ||
import { Order } from '../models/order.model'; | ||
|
||
class OrderRepo { | ||
async getOrders() { | ||
return await Order.find(); | ||
async getOrders(past: string) { | ||
let query = { | ||
status: { $in: [OrderStatusType.PENDING] }, | ||
}; | ||
|
||
if (past === 'true') { | ||
query = { | ||
status: { $in: [OrderStatusType.DELIVERED, OrderStatusType.CANCELLED] }, | ||
}; | ||
} | ||
|
||
return await Order.find(query).populate('products.product'); | ||
} | ||
|
||
async checkoutOrder(userId: string, totalPrice: Number, cart?: OrderItemType[]) { | ||
return await Order.create({ products: cart, totalPrice, created_by: userId }); | ||
} | ||
} | ||
export default new OrderRepo(); |
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Router } from 'express'; | ||
import { getAllOrders } from '../controllers/order.controller'; | ||
import OrderController from '../controllers/order.controller'; | ||
|
||
const orderRouter = Router(); | ||
|
||
orderRouter.get('/', getAllOrders); | ||
orderRouter.get('/', OrderController.getAllOrders); | ||
orderRouter.post('/checkout', OrderController.checkoutOrder); | ||
|
||
export default orderRouter; |
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
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
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
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