This is an Uber-like API (for mobility) developed in TypeScript with Nestjs, using TypeORM with PostgreSQL for data persistence. It integrates a demo payment gateway and allows cost calculation for a linear service by calculating distance, time, and adding a base fee. It uses native Axios within Nestjs to consume data.
This API was developed to be used with a PostgreSQL instance in Docker, so having Docker along with Node and Yarn are the prerequisites.
This project was developed on MacOS
- Clone the repository
git clone https://github.com/JuniorCarrillo/mobility-api.git
- Copy environments
cd mobility-api && cp .env.example .env
- Install dependencies (require Docker)
docker compose up -d && yarn make
- Run application
yarn start:dev
- Running on port 3000
open http://localhost:3000/docs
Here are listed the available endpoints or routes within the REST service. It should be noted that you can expand this information by accessing the Swagger generated from the same API at the /docs
endpoint, since security middleware, JWT, and route control by roles are implemented.
Request example:
curl --location 'http://localhost:3000/auth/driver/register' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Driver",
"password": "12345678",
"email": "driver@app.co"
}'
Response example:
{
"name": "Driver",
"email": "driver@app.co",
"role": "DRIVER",
"id": 1,
"createAt": "2023-04-15T21:01:17.399Z",
"updateAt": "2023-04-15T21:01:17.399Z"
}
Request example:
curl --location 'http://localhost:3000/auth/rider/register' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Rider",
"password": "12345678",
"email": "rider@app.co"
}'
Response example:
{
"name": "Rider",
"email": "rider@app.co",
"role": "RIDER",
"id": 2,
"createAt": "2023-04-15T21:01:58.395Z",
"updateAt": "2023-04-15T21:01:58.395Z"
}
Request example:
curl --location 'http://localhost:3000/auth/login' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"password": "12345678",
"email": "driver@app.co"
}'
Response example for rider:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiUklERVIiLCJzdWIiOjIsImlhdCI6MTY4MTU5MjU1MCwiZXhwIjoxNzEzMTUwMTUwfQ.QSXE4lz4D0IfmKdJNWjofOPWtvekvR5ybajO_RJiMH4",
"user": {
"id": 2,
"name": "Rider",
"email": "rider@app.co",
"role": "RIDER",
"createAt": "2023-04-15T21:01:58.395Z",
"updateAt": "2023-04-15T21:01:58.395Z"
}
}
Response example for driver:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiRFJJVkVSIiwic3ViIjoxLCJpYXQiOjE2ODE1OTI1ODMsImV4cCI6MTcxMzE1MDE4M30.umwXqvUNz2Ft48bKqIEwNC1RLGH2dkxWyP28GAVPNg0",
"user": {
"id": 1,
"name": "Driver",
"email": "driver@app.co",
"role": "DRIVER",
"createAt": "2023-04-15T21:01:17.399Z",
"updateAt": "2023-04-15T21:01:17.399Z"
}
}
Request example:
curl --location 'http://localhost:3000/user/card' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiUklERVIiLCJzdWIiOjIsImlhdCI6MTY4MTU5MjU1MCwiZXhwIjoxNzEzMTUwMTUwfQ.QSXE4lz4D0IfmKdJNWjofOPWtvekvR5ybajO_RJiMH4' \
--data '{
"number": "4242424242424242",
"cvc": "123",
"exp_month": "08",
"exp_year": "28",
"card_holder": "José Pérez"
}'
Response example:
{
"token": "tok_test_14154_3461ef5827d0C716Ec16f1649b67b3bA",
"brand": "VISA",
"last_four": "4242",
"exp_year": "28",
"exp_month": "08",
"id": 1,
"createAt": "2023-04-15T21:03:38.134Z",
"updateAt": "2023-04-15T21:03:38.134Z"
}
Request example:
curl --location 'http://localhost:3000/rider' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiUklERVIiLCJzdWIiOjIsImlhdCI6MTY4MTU5MjU1MCwiZXhwIjoxNzEzMTUwMTUwfQ.QSXE4lz4D0IfmKdJNWjofOPWtvekvR5ybajO_RJiMH4' \
--data '{
"location": [6.227613, -75.5799254],
"destination": [6.1664595, -75.625661],
"installments": 5
}'
Response example:
{
"location": [
6.227613,
-75.5799254
],
"destination": [
6.1664595,
-75.625661
],
"installments": 5,
"rider": {
"id": 2,
"name": "Rider",
"email": "rider@app.co",
"role": "RIDER",
"createAt": "2023-04-15T21:01:58.395Z",
"updateAt": "2023-04-15T21:01:58.395Z"
},
"driver": {
"id": 1,
"name": "Driver",
"email": "driver@app.co",
"role": "DRIVER",
"createAt": "2023-04-15T21:01:17.399Z",
"updateAt": "2023-04-15T21:01:17.399Z"
},
"card": {
"id": 1,
"token": "tok_test_14154_3461ef5827d0C716Ec16f1649b67b3bA",
"brand": "VISA",
"last_four": "4242",
"exp_year": "28",
"exp_month": "08",
"createAt": "2023-04-15T21:03:38.134Z",
"updateAt": "2023-04-15T21:03:38.134Z"
},
"id": 1,
"status": "REQUEST",
"finishAt": "2023-04-15T21:04:37.493Z",
"createAt": "2023-04-15T21:04:37.493Z",
"updateAt": "2023-04-15T21:04:37.493Z"
}
Request example:
curl --location --request POST 'http://localhost:3000/driver/finish/1' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiRFJJVkVSIiwic3ViIjoxLCJpYXQiOjE2ODE1OTI1ODMsImV4cCI6MTcxMzE1MDE4M30.umwXqvUNz2Ft48bKqIEwNC1RLGH2dkxWyP28GAVPNg0'
Response example:
{
"id": 1,
"location": [
6.227613,
-75.5799254
],
"destination": [
6.1664595,
-75.625661
],
"status": "COMPLETE",
"installments": 5,
"finishAt": "2023-04-15T21:05:20.454Z",
"createAt": "2023-04-15T21:04:37.493Z",
"updateAt": "2023-04-15T21:05:20.462Z",
"driver": {
"id": 1,
"name": "Driver",
"email": "driver@app.co",
"role": "DRIVER",
"createAt": "2023-04-15T21:01:17.399Z",
"updateAt": "2023-04-15T21:01:17.399Z"
},
"rider": {
"id": 2,
"name": "Rider",
"email": "rider@app.co",
"role": "RIDER",
"createAt": "2023-04-15T21:01:58.395Z",
"updateAt": "2023-04-15T21:01:58.395Z"
},
"card": {
"id": 1,
"token": "tok_test_14154_3461ef5827d0C716Ec16f1649b67b3bA",
"brand": "VISA",
"last_four": "4242",
"exp_year": "28",
"exp_month": "08",
"createAt": "2023-04-15T21:03:38.134Z",
"updateAt": "2023-04-15T21:03:38.134Z"
}
}
If you want to contribute to this project, please follow these steps:
- Fork the repository
- Create a branch (
git checkout -b feature/new-feature
) - Make the necessary changes and commit (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/new-feature
) - Open a pull request
MIT License © Junior Carrillo