- In this back-end project, a simple system of a Gym is used as a Proof of concept (POC) of TypeScript coding.
- A CRUD (Create, Update and Delete) protocol was used for manage two self-explained tables:
customers
andenrollments
. - The table
courses
(with gym courses in Portuguese) is already created in the database; - Furthermore, ranking routes are implemented, aggregating the
courses
andcustomers
metrics (see routes below).
- Example of
.env
file:
npm i
POSTGRES_USERNAME=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_PORT=
POSTGRES_DATABASE=
PORT=
npm run dev
npm run build
npm run start
βββ README.md
βββ package-lock.json
βββ package.json
βββ π src
β βββ π controllers
β β βββ courses.controllers.ts
β β βββ customers.controllers.ts
β β βββ enrollments.controllers.ts
β βββ π database
β β βββ connectionDB.ts
β β βββ dbdiagram.png
β β βββ dump.sql
β βββ index.ts
β βββ π middlewares
β β βββ courses.middlewares.ts
β β βββ customers.middleware.ts
β β βββ schemas.validation.ts
β βββ π protocols
β β βββ courses-rank.ts
β β βββ customer.ts
β β βββ customers-rank.ts
β β βββ enrollment.ts
β βββ π repositories
β β βββ courses.repository.ts
β β βββ customers.repository.ts
β β βββ enrollments.repository.ts
β βββ π routes
β β βββ courses.routes.ts
β β βββ customers.routes.ts
β β βββ enrollments.routes.ts
β β βββ index.ts
β βββ π schemas
β β βββ customer.schema.ts
β β βββ enrollment.schema.ts
β β βββ top-query.schema.ts
β βββ π services
βββ tsconfig.json
- POST
/register
- Send customer via body as follow
- If succeed, receive an answer in the format:
- PUT
/update/email
- Send the infos via body as follow
- If succeed, receive an answer in the format:
- POST
/enroll
- Send a body containing the following infos
- If succeed, receive an answer in the format:
- DELETE
/enroll
- Send a body containing the following infos
- If succeed, receive an answer in the format:
- GET
/rank/customers
- Optional a query
top
with a number, as the example below: - Response in the format:
- GET
/rank/courses
- Optional a query
top
with a number, as the example below: - Response in the format:
- GET
/courses/:customer_id
customer_id
is a number and required, as the example below:- Response in the format of an array, as shown below:
{
"name": "Customer Name",
"email": "test@test.com",
"cpf": "12345678910"
}
{
"message": "Customer_name was registered!"
}
{
"new_email": "new_email@example.com",
"previous_email": "previous_email@example.com"
}
{
"message": "Customer_name's email updated!"
}
{
"customer_id": "1",
"course_id": "2"
}
{
"message": "Success: Customer_X was enrolled into Course_X!"
}
{
"customer_id": "1",
"course_id": "2"
}
{
"message": "Success: Customer_X was unenrolled from Course_X!"
}
/rank/customers?top=3
[
{
"customer": "Γrick",
"courses": "5"
},
{
"customer": "Brun0",
"courses": "4"
},
{
"customer": "Jader",
"courses": "3"
}
]
/rank/courses?top=3
[
{
"course": "LPO",
"customers": "7"
},
{
"course": "Dança",
"customers": "5"
},
{
"course": "Zumba",
"customers": "3"
}
]
/courses/2
[
"Spining",
"Funcional",
"Dança",
"LPO",
"HidroginΓ‘stica"
]