API for a car rent store (In development).
Report Bug
·
Request Feature
This project is a RESTful API for a car rent store. The application it's still in development stage. The implemented features are:
- Users can create new account.
- Users can create a new session using their credentials.
- Users can create/update their avatar image.
- Users with admin privileges can create a new Category (each car should belongs to a category).
- Users with admin privileges can create a new Specification (each car can have multiple specifications).
- Users with admin privileges can add new cars.
- Users with admin privileges can add multiple images to each car.
- Users with admin privileges can add multiple specifications to each car.
- Users can see a list of all available cars and filter them by model, brand, and category.
- Users can rent cars.
The project was built using the following languages stacks:
- Node
- Typescript
- Express
- Docker
- PostgreSQL
- TypeORM
- Tsyringe
- Bcrypt
- Jsonwebtoken
- Class-transformer
- Class-validator
- Multer
To get a local copy up and running follow these simple example steps.
- Node
- NPM
- Yarn
- Clone the repo
git clone https://github.com/Torres-ssf/rent-car-api
- CD into the project root directory
cd rent-car-api/
- Install npm packages
yarn
This application uses Docker and Docker Compose and can be quickly initiate by simply running docker-compose up
. In order that to work you will need to have Docker and Docker Compose installed on your system. Docker will setup the database container, create the app and test database, setup the app container, and will start the app. The steps are:
- Run docker compose.
docker-compose up
After docker compose finishing initiate the application, you will see the log App launched at 3333 🚀
. Before using the application, it's necessary to run the migrations first.
- To run the migrations inside the docker container, we can simply use the following script:
yarn typeorm:docker migration:run
Now the application is ready to be used.
Setting up the application without Docker requires more steps.
-
After cloning the repo, make a copy of the
ormconfig.example.json
file and rename it toormconfig.json
. -
We need to edit the properties
user
,password
,port
, anddatabase
at theormconfig.json
. The values that you are going to use depends on how postgreSQL is setup on your system. After setting upuser
,password
, andport
we need to give the name of an existent database to thedatabase
property. By default, integration tests run on database calledrent_api_test_db
. We also need to create this database or integration tests are not going work. -
Now with the database properly setup, we can run the migrations:
yarn typeorm migration:run
- And finally, we can start the app:
yarn start:dev
If everything was done properly, a log message will appear at the terminal: Server started on port 3333!
It is possible to explore all API endpoints using an interactive documentation created with Swagger UI. After the application is running you can open the browser at http://localhost:3333/documentation
and start using it.
Many of the endpoints are reserved to admin users. There is a script to easily create an admin. After setting up the Db connection, you can simply run:
yarn seed:admin
An admin user will be created with the following credentials:
email: john.admin@email.com
password: Aa123456
To be able to tests login required endpoint at the Swagger Documentation, you will need first to use a jwt token to gain authorization. The steps are the following:
- At the documentation page, we will use the session endpoint to generate an jwt token. Click at
Try it out
- Give the admin credentials and click on the execute button:
- Copy the generated token from the response object:
- Click on the
Authorize
button at the top of the page:
- Insert the token in the value input and then click on
Authorize
:
- Now all endpoints can be used within the documentation.
This application has unit and integrations tests. Integration tests are running in a database named rent_api_test_db
by default. This database is created by the docker-compose file. If you are not using Docker, it needs to be created manually.
To run the tests we can simply run the following script.
yarn test
This application is still in development process and unit and integration tests are being written as the application grows, following TDD.
👤 Torres-ssf
- Github: @Torres-ssf
- Twitter: @torres_ssf
- Linkedin: torres-ssf
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
This project is MIT licensed.