2022-05-24 01:48:50 +00:00
# Shelf Project
2022-04-19 14:47:00 +00:00
2022-05-24 01:48:50 +00:00
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.
2022-05-24 17:42:02 +00:00
2022-05-24 20:34:31 +00:00
# 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:
2022-05-24 20:43:48 +00:00
`docker exec -it shelf-postgres-1 /bin/bash`
`psql -U postgres`
`CREATE DATABASE shelf_test`
2022-05-24 17:42:02 +00:00
# Installation
2022-05-24 20:34:31 +00:00
- Install packages dependencies: `npm install`
- Run tests: `npm run test`
- Run the database: `npm run up`
- Launch the application: `npm run start`
2022-05-24 17:42:02 +00:00
2022-05-24 20:34:31 +00:00
Note : If needed you can reset the tables by closing the app and running the following commands:
2022-05-24 19:09:28 +00:00
- `npm run down`
- `npm run up`
2022-05-24 17:42:02 +00:00
# Availaible endpoints
- Products :
2022-05-24 19:09:28 +00:00
| 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 ) |
2022-05-24 17:55:47 +00:00
2022-05-24 17:42:02 +00:00
- Users :
2022-05-24 19:09:28 +00:00
| 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
2022-05-24 17:42:02 +00:00
2022-05-24 19:09:28 +00:00
| 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 ) |
2022-05-24 17:42:02 +00:00
# Built with
- Typescript
2022-05-24 19:09:28 +00:00
- Node
- Express
- Dotenv
2022-05-24 20:34:31 +00:00
- Docker
- Postgres
2022-05-24 19:09:28 +00:00
- Db-migrate
- Jsonwebtoken
- Jasmine
2022-05-24 20:34:31 +00:00
- Supertest
2022-05-24 17:42:02 +00:00
# Author
Anis Benziane.