chicken-sloths / bangazon-api-sprint1

API for a mock Amazon + Etsy platform providing developers access to the company's employee & product data
0 stars 0 forks source link

Cascading Orders Delete #122

Closed TimAConner closed 6 years ago

TimAConner commented 6 years ago

Description

Adds cascading delete when you delete an order, so that product_orders rows associated with the order are also deleted. Also added minor JavaScript styling changes to the OrdersModel.

Related Ticket(s)

Completes Issue #110 (Add Cascading Delete to Order Table/ Product_Order Join Table)

Problem to Solve

Product_orders entries were not being deleted when an order was deleted. When an order is deleted, the product_order entries associated with it should be deleted too.

Proposed Changes

Add ON DELETE CASCADE to Product_Orders table on the foreign_key order_id.

Expected Behavior

When you delete an order, all product_orders associated with it should be deleted too.

Steps to Test Solution

  1. run npm run db:generate
  2. run npm start
  3. In your browser, go to http://localhost:8080/api/v1/orders/<An Order's ID with Products>
    1. If that order does not have any products on it, find one that does.
  4. In your database browser, run SELECT * FROM "Product_Orders" WHERE order_id = <An Order's ID with Products>;
    1. A list of products should appear.
  5. In Postman, run DELETE http://localhost:8080/api/v1/orders/<An Order's ID with Products>
  6. In your database browser, run SELECT * FROM "Product_Orders" WHERE order_id = <An Order's ID with Products>;
    1. All product orders should be deleted.
    2. You may have to refresh the database.
jordan-castelloe commented 6 years ago

testing!