This project is an API for a store website.
This API uses various technologies to achieve the required functionality:
- Postgres for the database
- Node/Express for the application logic
- dotenv from npm for managing environment variables
- db-migrate from npm for migrations
- jsonwebtoken from npm for working with JWTs
- jasmine from npm for testing
- ESLint for linting the code.
- Prettier for formatting the code to be consistent.
- TypeScript
- nodemon for automatic reload at development stage
- postgres for data base
- Create user with password and additional ,data will be stored inside DB.
- Open new order for users.
- Add products into your cart.
- Gather information about users, products and orders for logged in users.
- Delete your profile.
- Update your user profile data.
- Show user dashboard.
- create main DB:
- run ( CREATE DATABASE shopping; ) to create a data base on your machine called "shopping"
- create a user on postgres by running ( CREATE USER shopping_user WITH PASSWORD 'password123'; )
- run '\c shopping' to connect to our DB.
- run ( GRANT ALL PRIVILEGES ON DATABASE shopping TO shopping_user; ) so we can access and edit on our DB.
- Create test DB -if you want to perform testing using jasmine- :
- run ( CREATE DATABASE shopping_test; ) to create a data base on your machine called "shopping_test"
- create a user on postgres by running ( CREATE USER shopping_user_test WITH PASSWORD 'password123'; )
- run ( \c shopping_test ) to connect to our DB.
- run ( GRANT ALL PRIVILEGES ON DATABASE shopping_test TO shopping_user_test; ) so we can access and edit on our DB Via our newly created user.
- clone the project
- run 'npm install' , to install all th needed packages
- run 'npm install -g db-migrate' to install db-migrate globally so we can migrate tables to our DB.
- run 'db-migrate up' to create all of our DB tables to interact with our node project.
- to delete all created tables at once, run "db-migrate reset" , don't run "db-migrate down" because it wont delete tables with foreign-key constrains.
- within console, run (npm install) to install all the needed packages
-
This project needs Environment variables to be able to run as expected, but because this variables could be a sensitive info so you need to give your values for some of them.
-
I will provide the variables names, then you should give them values:
-
create (.env) file in the root folder of the app
-
the variables are:
DATABASE_HOST = POSTGRES_DB = shopping POSTGRES_USER = shopping_user POSTGRES_PASSWORD = pasword123 ENV = dev POSTGRES_test_DB = shopping_test POSTGRES_USER_test = shopping_user_test SALT_NO = <this is the number of hashing cycles for password hashing, you could add any number> BCRYPT_PASS = <this the added salt on user password before hashing, you could add any string but keep it secure and dont change it or you will lose your data in DB> TOKEN_PASS = <this is the password used for creating and verifying user tokens, you can add any string but keep it secure and dont change it>
-
add the provided variables with your values to them inside (.env) file.
- within console run (npm run start) this will start a server for you to interact with the API either using postman or any browser.
- I will state how to use it in details inside REQUIRMENTS.md.
- (npm run prettier) => for formatting the code.
- (npm run lint) => for lint the code, for better syntax.
- (npm run start) => to start the API server.
- (npm run test) => to test all methods and endpoint using jasmine at development phase.
-
This DB have four tables, each table with specific purpose, all tables are connected to each other with foreign keys.
- Users => all the users data
- product => information about all products
- orders => all orders created with their associated products
- orders_products => many to many table that have relations between orders created and their associated users.
-
Users:
id SERIAL PRIMARY KEY, f_name VARCHAR(50), l_name VARCHAR(50), user_name VARCHAR(50) NOT NULL, password text NOT NULL , age INTEGER
-
product:
id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, price INTEGER NOT NULL, category VARCHAR (100)
-
orders:
id SERIAL PRIMARY KEY, status VARCHAR(15) DEFAULT 'open', user_id BIGINT REFERENCES users(id) NOT NULL
-
orders_products:
id SERIAL PRIMARY KEY, quantity INTEGER NOT NULL, order_id BIGINT NOT NULL REFERENCES orders(id), product_id BIGINT NOT NULL REFERENCES product(id)