Shelf/README.md

132 lines
4.3 KiB
Markdown

# Shelf Project
An online storefront to showcase products. Users is able to browse an index of all products, see the specifics of a single product, and add products to an order that they can view in a cart page.
# Pre-requisite
- Add a `.env` file in /Shelf folder with the following :
```
POSTGRES_HOST=127.0.0.1
POSTGRES_DB=shelf
POSTGRES_TEST_DB="shelf_test"
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
ENV=dev
BCRYPT_PASSWORD=speak-friend-and-enter
SALT_ROUNDS=10
TOKEN_SECRET=alohomora123!
TOKEN_SECRET_TEST=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoxLCJmaXJzdG5hbWUiOiJKb2huIiwibGFzdG5hbWUiOiJEb2UiLCJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZF9kaWdlc3QiOiIkMmIkMTAkeXNkTHQuUjVqdjFJdHVzTk5NMGJNLlU0RkZvbmJRYUV2VFBsVnFhQWJqSkV3NTdzTEZwVGEifSwiaWF0IjoxNjUzMjUzODIxfQ.rdC42gcdhzAwnwwVJxmhBLVK5tvf2zONG3UcHLU6xE0`
```
- Inside shelf folder mount the container: `docker compose up`
- Create shelf_test database with the following commands:
`docker exec -it shelf-postgres-1 /bin/bash`
`psql -U postgres`
`CREATE DATABASE shelf_test`
# Installation
- Install packages dependencies: `npm install`
- Run tests: `npm run test`
- Run the database: `npm run up`
- Launch the application: `npm run start`, you can acces the application with this link `127.0.0.1:3000`
Note : If needed you can reset the tables by closing the app and running the following commands:
- `npm run down`
- `npm run up`
# Availaible endpoints
- Products :
| HTTP Verb | Endpoint | CRUD |
|:--------------:|:--------------------|:-----------------|
| Get | `/products` | Index |
| Get | `/products/:id` | Read |
| Post | `/products` | Create ( Token ) |
| Put | `/products/:id` | Update ( Token ) |
| Delete | `/products/:id` | Delete ( Token ) |
- Users :
| HTTP Verb | Endpoint | CRUD |
|:--------------:|:--------------------|:-----------------------|
| Get | `/users`, | Index ( Token ) |
| Get | `/users/:id` | Read ( Token ) |
| Post | `/users` | Create |
| Put | `/users/auth` | Authenticate ( Token ) |
| Put | `/users/:id` | Update ( Token ) |
| Delete | `/users/:id` | Delete ( Token ) |
- Orders
| HTTP Verb | Endpoint | CRUD |
|:--------------:|:-----------------------|:-----------------|
| Get | `/orders`, | Index ( Token ) |
| Get | `/orders/:id` | Read |
| Post | `/orders` | Create |
| Post | `/orders/:id/products` | Create ( Token ) |
| Delete | `/orders/:id/products` | Delete ( Token ) |
# Data shapes
- Products :
| Column | Type |
|:-------:|:-----------------------|
| id | SERIAL PRIMARY KEY |
| name | VARCHAR(250) NOT NULL |
| price | INTEGER NOT NULL |
- Users :
| Column | Type |
|:------------:|:-----------------------|
| id | SERIAL PRIMARY KEY |
| firstName | VARCHAR(250) NOT NULL |
| lastName | VARCHAR(250) NOT NULL |
| username | VARCHAR(250) NOT NULL |
| password | VARCHAR(250) NOT NULL |
- Orders :
| Column | Type |
|:------------:|:---------------------------------------|
| id | SERIAL PRIMARY KEY |
| status | VARCHAR(15) |
| user_id | INTEGER NOT NULL REFERENCES users(id) |
- Orders Products :
| Column | Type |
|:-------------:|:------------------------------------------|
| id | SERIAL PRIMARY KEY |
| quantity | INTEGER NOT NULL, |
| order_id | INTEGER NOT NULL REFERENCES orders(id) |
| product_id | INTEGER NOT NULL REFERENCES products(id) |
# Built with
- Typescript
- Node
- Express
- Dotenv
- Docker
- Postgres
- Db-migrate
- Jsonwebtoken
- Jasmine
- Supertest
# Author
Anis Benziane.