Backend for pokeweb, an E-commerce web app.
Apollo is used with Express for the API which listens for requests from the graphql client in the frontend. Graphql resolvers and entities are made with type-graphql.
Mikro-orm is used to generate the SQL for the database. Configuring mikro-orm.config.ts will be necessary to properly link the backend to one.
User passwords are hashed with argon2 before being stored in the database.
express-session is used for user authentication by sending and recieving cookies from a web client.
connect-redis is express middleware which is used for storing cookies for user authentication. You need redis installed on your machine for this to work properly.
Some diagrams I made in ms paint showing how I designed the backend.
- postgresql or another mikro-orm supported database needs to be installed with 'mikro-orm-config.ts' configured
- redis also needs to be installed for the backend to work
There's probably a better way to do this but this works fine I guess.
- Copy json file into /tmp folder since /home might have restricted access with psql
- Set psql variable name to json data (we can echo to double check the value)
\set $var `cat /tmp/PRODUCTS.json`
\echo :$var
- Create a temp table that holds our entire json array in a single row
CREATE temp TABLE $tableName ( $colName jsonb );
INSERT INTO $tableName VALUES (:'$var');
- Split json array into table with proper columns for ease of use
CREATE temp TABLE t1 AS
select * from jsonb_to_recordset((select * from t))
AS x(cost int, name text, text text, effect text, "itemId" int, sprite text, "nameEng" text, category text);
- Copy our table from step 4 directly into the "product" table
INSERT INTO product (item_id, name, name_eng, cost, effect, text, sprite, category, created, updated)
SELECT "itemId", name, "nameEng", cost, effect, text, sprite, category, CURRENT_DATE, CURRENT_DATE FROM t1;
- need to explicitly define sessions object types instead of my hacky workaround