Welcome to the Trybesmith project repository!!
Introduction
API developed to manage a fictional store of medieval items, using TypeScript and following REST principles.
Among the features, you can register a new user, login to get the token that is needed to manipulate the database, list products and add new products, list orders and add new orders.
Basically, it is possible to perform the basic operations that can be done on a given database: Creation, Reading, Update and Deletion (CRUD) in the MySQL database.
Installation
Installation instructions
Clone the repository
git clone git@github.com:lucas-da-silva/project-trybesmith.git
Enter the repository
cd project-trybesmith
Climbing the containers (docker is needed)
docker-compose up -d
Entering the Node.js container
docker exec -it trybesmith bash
Install dependencies
npm install
Trybesmith.sql
Run the mysql scriptCopy and paste into an SQL tab or open the script and run it.
It will create the database, the tables and insert the values.
Run the application
npm start
You can use Thunder Client or Insomnia (or whatever) to check API routes.
To stop containers
docker-compose down
Aplication
As the project was developed using TypeScript, functions, objects and function parameters were typed, ensuring greater readability and functionality of the application.
The MSC (Model, Service, Controller) software architecture was used to organize the project structure.
The jwt library was also used to generate a token, which is necessary to have complete access to the application.
There are multiple validations to perform a request, from middlewares
and functions dedicated to validations, so pay attention to what is expected when making a request.
Products routes
-
GET /products
: lists allproducts
in the database; -
POST /products
: register a newproduct
;
The request body should follow the format below
{
"name": "Espada longa",
"amount": "30 peças de ouro"
}
Users routes
POST /users
: adds a newuser
to the database and returns atoken
;
The request body should follow the format below
{
"username": "MAX",
"vocation": "swordsman",
"level": 10,
"password": "SavingPeople"
}
Login routes
POST /login
: with valid username and password (registered in the database) returns atoken
;
The request body should follow the format below
{
"username": "string",
"password": "string"
}
Orders routes
-
GET /orders
: lists allorders
in the database; -
POST /orders
: adds a neworder
to the database and updates theproducts
with the createdorder
;
To register new orders, it is necessary to have a
token
in theAuthorization
key in the request.
The request body should follow the format below
{
"productsIds": [1, 2]
}
- The values that are in the array will be inserted in the products (
table products
) in theorder_id
column;