Git Product home page Git Product logo

pokemart's Introduction

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

pokemart's People

Contributors

ansxnlee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.