Closed jordan-castelloe closed 6 years ago
testing!
Regarding your note:
I'm happy to pull it in for MVP and work out the details later. But, yes, orders presumably won't have a payment_type_id
.
Fixed the bug with deleting and getting orders (thanks @DavidLarsKetch)! Now you should be able to delete an order, try to get the same order, and get a friendly 404 error back. I just realized we should probably delete all associated products and product_orders when we delete an order, but I think that might be a new PR/ new issue for the sake of expediency
Description
Adds the following endpoints:
GET /orders
: gets all ordersGET /orders/:id
: gets one order by idPOST /order
: posts new orderPUT /orders/:id
: updates one order by idDELETE /orders/:id
: removes one order by idRelated Ticket(s)
fixes #4 and #10
Steps to Test Solution
npm run db:generate
Comment out non-orders routes
npm start
to start your server.http://localhost:8080/api/v1/orders
should give you all the ordershttp://localhost:8080/api/v1/orders/10
should give you information about that order with an array of products associated on that order. The format should look like this, as specified in issue #10:POST the following JSON to
http://localhost:8080/api/v1/orders
:{ "customer_id": 0, "payment_option_id": 100 }
Should return 35 and you should be able to run aGET
forhttp://localhost:8080/api/v1/orders/35
and see the stuff you just posted plus an empty array where products would normally be.PUT the following JSON to
http://localhost:8080/api/v1/orders/1
{ "customer_id": 0, "payment_option_id": 100 }
Run aGET
forhttp://localhost:8080/api/v1/orders/1
. You should see that the customer_ids and payment_option_ids on each product object have changed to 0 and 100.Run a DELETE on
http://localhost:8080/api/v1/orders/35
and it should return35
.A couple other notes
I didn't really do error handling on the orders route (checking to make sure all the info was passed in, etc) because I figure when orders are created they won't have a payment_type_id? And then that'll get added later? I honestly can't remember if we decided on a way to handle that or not. If anyone remembers or has a concrete idea, I'd be glad to include it on this PR. Otherwise, we can go ahead and merge this in for basic MVP functionality and work out the details post-MVP.