Check out the README for a more detailed description of the project.
[git hub link](https://github.com/SeanPaulson/e-commerce)
Summary:
Fun project I took me about a month 3hrs a day 5 days a week.
Some notes about my project:
-Created with typescript (added some interesting challenges)
-Learned PG/PLpostgres
moved alot of the pg sql scripts from the controllers and created PLpostgress functions and procedures.
The Cart checkout is handled completely by a postgress procedure.
-- PROCEDURE: commerce.checkout(integer)
-- DROP PROCEDURE IF EXISTS commerce.checkout(integer);
CREATE OR REPLACE PROCEDURE commerce.checkout(
IN uid integer)
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE item RECORD;
DECLARE order_details_id integer;
BEGIN
RAISE NOTICE 'storing user order info...';
INSERT INTO commerce.order_details (
user_id,
total
)
SELECT user_id, sum(total) FROM commerce.get_user_cart($1)
GROUP BY user_id
RETURNING id INTO order_details_id;
INSERT INTO commerce.order_items (order_id, product_id, quantity)
SELECT DISTINCT ON (prod_id) order_details_id, prod_id, quantity
FROM commerce.cart_items
JOIN commerce.order_details
ON order_details.user_id = cart_items.user_id
WHERE cart_items.user_id = $1;
RAISE NOTICE 'removing cart item from product inventory and storing order information...';
FOR item IN
SELECT quantity, prod_id, user_id FROM commerce.cart_items WHERE user_id = $1
LOOP
BEGIN
RAISE NOTICE 'updating product inventory';
UPDATE commerce.product_inventory
SET quantity = quantity - item.quantity WHERE product_id = item.prod_id ;
EXCEPTION
WHEN SQLSTATE '23514' THEN
RAISE EXCEPTION 'check constraint non negative %', item
USING COLUMN=item.prod_id, ERRCODE='23514';
END;
END LOOP;
RAISE NOTICE 'updated product inventory';
RAISE NOTICE 'deleting user_cart';
DELETE FROM commerce.cart_items;
RAISE NOTICE 'Order Complete!';
RETURN;
END;
$BODY$;
ALTER PROCEDURE commerce.checkout(integer)
OWNER TO postgres;
It took me a bit longer to complete this project because I was trying to dive deeper into postgress.
I was(am) reading the book - designing data intensive applications by Martin Kleppmann
Highly recommend this book.
We hope you enjoyed this project!