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

Add Order History Schema and Implement CRUD API #868

Closed
IkkiOcean opened this issue Nov 8, 2024 · 2 comments · Fixed by #875
Closed

Add Order History Schema and Implement CRUD API #868

IkkiOcean opened this issue Nov 8, 2024 · 2 comments · Fixed by #875
Assignees

Comments

@IkkiOcean
Copy link
Contributor

Description:

We need to add an Order History schema in the database to track the details of the orders placed by users. The schema should be able to store information such as the products ordered, order status, user details, payment information, and timestamps. We will also implement the necessary CRUD APIs (Create, Read, Update, Delete) for interacting with this data.


Steps to Implement:

  1. Database Schema:

    • Create OrderHistory Schema:
      • Design and implement an OrderHistory schema that includes the following fields:
        • orderId (unique identifier)
        • userId (reference to the user who placed the order)
        • orderDate (timestamp when the order was placed)
        • orderStatus (e.g., "Pending", "Shipped", "Delivered")
        • totalAmount (total value of the order)
        • shippingAddress (address for shipping)
        • paymentStatus (e.g., "Paid", "Pending")
        • items (array of product IDs with quantity, price per unit, etc.)
        • trackingNumber (optional, for shipped orders)
      • Use references to other collections where necessary (e.g., products, users).
      • Add timestamps (createdAt, updatedAt) to track when records are created and updated.
  2. Create CRUD APIs for Order History:

    • Create Order (POST /api/orders):

      • Endpoint to allow users to create a new order.
      • Accept input such as user ID, order items (product IDs with quantities), payment details, and shipping address.
      • Insert the order data into the OrderHistory collection and return a confirmation with the order ID and details.
    • Read Orders (GET /api/orders):

      • Endpoint to fetch all orders for a specific user.
      • Fetch order details from the OrderHistory schema and return data such as:
        • Order ID
        • Order date
        • Status
        • Total amount
        • Items ordered (product name, quantity, price, etc.)
      • Optionally, implement pagination to manage large order datasets.
      • Authorization: Ensure that only the authenticated user can view their own orders.
    • Update Order Status (PUT /api/orders/:orderId):

      • Endpoint to update the status of an existing order (e.g., from "Pending" to "Shipped").
      • Accept data like the new order status and tracking number (if applicable).
      • Ensure that only the admin or the user who placed the order can update the status.
    • Delete Order (DELETE /api/orders/:orderId):

      • Endpoint to allow users to delete an order if it's in a certain status (e.g., "Pending").
      • Only the user who placed the order should be able to delete it, or the admin should have broader access.
      • Ensure that the order is properly removed from the database.
  3. Backend Logic:

    • Handle Order Validation:
      • Validate order data before saving it (e.g., ensure that the user exists, products are valid, quantities are available, etc.).
      • Handle scenarios such as failed payments or invalid shipping addresses.
    • Error Handling:
      • Implement proper error messages for invalid data, unauthorized access, or any other errors during CRUD operations.
Copy link
Contributor

github-actions bot commented Nov 8, 2024

Thank you for creating this issue! 🎉 We'll look into it as soon as possible. In the meantime, please make sure to provide all the necessary details and context. If you have any questions or additional information, feel free to add them here. Your contributions are highly appreciated! 😊

You can also check our CONTRIBUTING.md for guidelines on contributing to this project.

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Hello @IkkiOcean! Your issue #868 has been closed. Thank you for your contribution!

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

Successfully merging a pull request may close this issue.

2 participants