Skip to content

ansxnlee/pokemart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pokemart

Backend for pokeweb, an E-commerce web app.

Technologies used

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.

Showcase

Some diagrams I made in ms paint showing how I designed the backend.

erd

architecture

Additional development setup

  • 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

Importing PRODUCTS.json into postgres

There's probably a better way to do this but this works fine I guess.

  1. Copy json file into /tmp folder since /home might have restricted access with psql
  2. Set psql variable name to json data (we can echo to double check the value)
\set $var `cat /tmp/PRODUCTS.json`
\echo :$var
  1. 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');
  1. 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);
  1. 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;

Areas for improvement

  • need to explicitly define sessions object types instead of my hacky workaround