E-commerce API made with typescript, express ,PostgreSQL with all the basic features and more !!
- Nodejs
- Expressjs
- Typescript
- PostgreSQL
- db-migrate(tool) !important for doing migration stuff.
- Node & NPM ⬇️ - (node v16), (npm v8)
- PostgreSQL ⬇️ - (v14)
- Docker ⬇️ (optional)
1- docker-compose up --build -d // for building and starting the containers.
2- docker-compose down // for stoping containers.
ENV=dev
DB_HOST=127.0.0.1
DB_NAME=store_front_api_dev
DB_USERNAME=admin_user
DB_TEST_NAME=store_front_test_api
DB_TEST_USERNAME=test_admin_user
DB_PASSWORD=password123
JWT_KEY=jsonwebtokensecret22
EXTRA_PASSWORD=22endof@year
- first connect to psql
- Ubuntu
sudo -u postgres psql
- windows
psql -U postgres
- create the database
- developement db
// .
CREATE USER admin_user WITH PASSWORD 'password123';
CREATE DATABASE store_front_api_dev;
\c store_front_api_dev
GRANT ALL PRIVILEGES ON DATABASE store_front_api_dev TO admin_user;
- testing db
CREATE USER test_admin_user WITH PASSWORD 'password123';
CREATE DATABASE store_front_test_api;
GRANT ALL PRIVILEGES ON DATABASE store_front_test_api TO test_admin_user;
- setup database.json file (incase you created the db using the commands upove use the same json below.)
{
"dev": {
"driver": "pg",
"host": "127.0.0.1",
"database": "store_front_api_dev",
"user": "admin_user",
"password": "password123"
},
"test": {
"driver": "pg",
"host": "127.0.0.1",
"database": "store_front_test_api",
"user": "test_admin_user",
"password": "password123"
}
}
- db-migrate .
- To install db-migrate
npm i -g db-migrate
- after installaion run
db-migrate up
- to install dependencies :
npm install
- to start the app :
npm start
- to run the test:
npm run test
⭕ YOU CAN ACCESS THE SERVER IN localhost:3000
http://localhost:3000/api/
- please note that the body should be send in JSON formate
Routes | Method | Description | Schema |
---|---|---|---|
Users | |||
/api/users | POST | Register a User | {firstname: string, lastname: string, email: string, password: string} |
/api/users/login | POST | Login A user | {email:string, password:"string"} |
/api/users/me | GET | Get A user profile | |
/api/users/:id | GET | Get A user By Id | |
Products | |||
/api/products | GET | Get Products | |
/api/products/:id | GET | Get Individual product | |
/api/products/:id | DELETE | Delete A Product | |
/api/products | POST | Insert A Product | {price: number, title: string, summary:string, image_url:string} |
/api/products/:id | PATCH | Update Product | it could be the same fields as post request or less |
Orders | |||
/api/orders | GET | Gets Order | |
/api/orders/:id | GET | Get Individual Order Detailes | |
/api/orders | POST | Add new order | {customer_id: number, total: number, order_status: string, payment_type: string} |
/api/orders/:id | PATCH | Update Order | it could be the same fields as post request or less |
/api/orders/:id | DELETE | Delete Order | |
/api/orders/products | POST | add products to order | {products: [{product_id: number, quantity: number}]} |
/api/orders/products/:pid | POST | add product to order | {quantity: number} |
- /api/users/:id > (GET)
- /api/users/me > (GET)
- /api/products/ > (POST)
- /api/products/:id > (DELETE - PATCH)
- All orders endpoints withe > (POST - GET - PATCH - DELETE)
- You should provide a Bearer token in authorization header as shown below.