Skip to content
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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

Tanyaa-a
Copy link
Collaborator

@Tanyaa-a Tanyaa-a commented Jan 7, 2025

Description

add controller for order and routes

Changes

Related issues

Screenshots

  • Create order from cart
Screenshot 2025-01-06 at 9 24 54 PM
  • get orders
Screenshot 2025-01-06 at 9 25 16 PM
  • Get spesific order
Screenshot 2025-01-06 at 9 26 56 PM
  • Change order status
Screenshot 2025-01-06 at 9 29 02 PM

}
};

const cancelOrder = async (req, res, next) => {
Copy link
Collaborator

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.

@vrudnitskaya
Copy link
Collaborator

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)}`,
Copy link
Collaborator

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({
Copy link
Collaborator

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)}

try {
const { id: orderId } = req.params;
const order = await Order.findByIdAndUpdate(orderId, { status: 'Cancelled' }, { new: true, runValidators: true });

Copy link
Collaborator

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?

Copy link
Collaborator

@benochi benochi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants