-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rb 64 controllers routes for order #28
base: dev
Are you sure you want to change the base?
Conversation
src/controllers/orderController.js
Outdated
} | ||
}; | ||
|
||
const cancelOrder = async (req, res, next) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to specify who is allowed to cancel the order and check their ID to confirm whether they are the user or the buyer of this order.
Great job, Tanya! Please pay attention to my comments. |
const orderAmount = calculateCartTotal(tempCart, buyerLocation, sellerLocation); | ||
|
||
const order = await Order.create({ | ||
orderNumber: `ORD-${Date.now()}-${sellerId.slice(-5)}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you test that invalid data can't throw an error here, like a missing createdBy(if we are validating that, then it should never be missing so its pretty solid, but always good to check.
const sellerLocation = items[0].book.createdBy.location; | ||
const orderAmount = calculateCartTotal(tempCart, buyerLocation, sellerLocation); | ||
|
||
const order = await Order.create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a NOTE: You would want to use UUID to avoid collisions in real world scenarios:
ORD-${Date.now()}-${sellerId.slice(-5)}
src/controllers/orderController.js
Outdated
try { | ||
const { id: orderId } = req.params; | ||
const order = await Order.findByIdAndUpdate(orderId, { status: 'Cancelled' }, { new: true, runValidators: true }); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is all order related data correctly cleaned up on cancel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see notes
Description
add controller for order and routes
Changes
Related issues
Screenshots