Project made during Trybe web development course.
It is an application built with Node.js, Express, TypeScript, MySQL database, library for Joi validation, library for creation and verification of JWT token.
The API follows the REST API standard and with it it is possible to perform CRUD (Create, Read, Update, Delete) in a database that simulates a store.
Application layers: Model, Service and Controller;
-
Clone the repository: git@github.com:marinafischer/trybesmith.git
-
To start with node:
- Install dependencies: npm install
- Create a .env file in the project root with the variables expected by the connection;
- Create the database (Trybesmith.sql)
- Start the application: npm start
-
To start with docker:
- Run the command: docker-compose up -d
- Run the command: docker exec -it trybesmith bash This command will give access to the container terminal, from here it is possible to run the same commands used with node (described above);
- The endpoint queries the database;
- Returns status 200 and all bank products;
- The endpoint registers a new product;
- The endpoint must receive the following structure:
{
"name": "Longsword",
"amount": "30 gold pieces"
}- If any data is not informed, the API returns status 400 and an error message;
- If the registration is successful, the API returns status 201 and product data;
- The endpoint registers a new user;
- The endpoint must receive the following structure:
{
"username": "string",
"class": "string",
"level": 1,
"password": "string"
}- If any data is not informed, the API returns status 400 and an error message;
- If the registration is successful, the API returns status 201 and an access token;
- The endpoint queries the database;
- The route returns status 200 and the orders and product
ids associated with them.
- The route receives the
usernameandpasswordfields, and these fields are validated in the database; - A
JWTtoken is generated and returned if successful; - The endpoint must receive the following structure:
{
"username": "string",
"password": "string"
}- If the data is incorrect, the API returns status 400 and an error message;
- The endpoint registers a new request;
- The request will only be created if the user is logged in (send the token through the request header using the Authorization key);
- The orders sent are saved in the
Orderstable and theProductstable is updated in all products with theidincluded in theproductsIdskey of the requisition, and adding in these products theorderIdof the newly created order; - The endpoint must receive the following structure:
{
"productsIds": [1, 2]
}- If the token or json data is incorrect, the API returns status 400 and an error message;