https://github.com/rafaelmoraes003/car-shop
CRUD API for a vehicle dealership with a MongoDB database.
https://github.com/rafaelmoraes003/car-shop
chai docker express http-server mocha mongodb mongoose nodejs oop sinon solid-principles typescript unit-testing zod
Last synced: 3 months ago
JSON representation
CRUD API for a vehicle dealership with a MongoDB database.
- Host: GitHub
- URL: https://github.com/rafaelmoraes003/car-shop
- Owner: rafaelmoraes003
- Created: 2022-10-23T01:13:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-14T02:51:17.000Z (over 3 years ago)
- Last Synced: 2025-03-21T10:52:46.820Z (over 1 year ago)
- Topics: chai, docker, express, http-server, mocha, mongodb, mongoose, nodejs, oop, sinon, solid-principles, typescript, unit-testing, zod
- Language: TypeScript
- Homepage:
- Size: 234 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Car Shop
###
In this project, a CRUD API was created for a car dealership with a MongoDB database.
For the development of the API, ODM Mongoose was used to connect the database with Node.js .
The project uses the MSC (Model-Service-Controller) architecture, Object Orientation following the SOLID principles with TypeScript and unit tests made with Mocha, Chai and Sinon, which cover 100% of the lines of code from the project.
###
Technologies used
###
###
How to use the application
Clone the application using the `git clone` command. After that, enter the project folder using the `cd car-shop` command.
###
🐳 Running through Docker
- Inside the project folder, use the `docker-compose up -d` command. It is responsible for uploading the Node.js API and the MongoDB database.
- Enter the container's terminal via the `docker exec -it car_shop bash` command.
- Inside the container, install the necessary dependencies using the `npm install` command.
- Finally, still inside the container's terminal, to initialize the API, use the `npm run dev` command.
> The API is on port `3001` on localhost.
Running locally
- Inside the project folder, use the `npm install` command to install the necessary dependencies.
- Put the MongoDB URI in the `./src/models/connection.ts` file in the `MONGO_DB_URL` variable.
- Use the `npm run dev` command to initialize the API.
> The API is on port `3001` on localhost.
###
Unit tests and test coverage
- To run the unit tests, use the `npm run test:dev` command.
- To verify test coverage, use the `npm run test:coverage` command.
###
Endpoints
Cars
| Method | Functionality | URL |
|---|---|---|
| `POST` | Create new car | http://localhost:3001/cars |
| `GET` | List all cars | http://localhost:3001/cars |
| `GET` | List a car based on its _id | http://localhost:3001/cars/:id |
| `PUT` | Update a car based on its _id | http://localhost:3001/cars/:id |
| `DELETE` | Delete a car based on its _id | http://localhost:3001/cars/:id |
#### The `POST` and `PUT` endpoints require a JSON object in the following format:
```JavaScript
{
model: "Ferrari Maranello",
year: 1963,
color: "red",
buyValue: 3500000,
status: true,
seatsQty: 2,
doorsQty: 2
}
```
- About the properties of the above object, it is important to know:
```JavaScript
{
model: String with at least 3 characters
year: Number greater than or equal to 1900 and less than or equal to 2022
color: String with at least 3 characters
buyValue: Integer
status: Optional property, indicates whether or not the car can be purchased (boolean)
seatsQty: Number greater than or equal to 2 and less than or equal to 7
doorsQty: Number greater than or equal to 2 and less than or equal to 4
}
```
###
Motorcycles
| Method | Funcionality | URL |
|---|---|---|
| `POST` | Create new motorcycle | http://localhost:3001/motorcycles
| `GET` | List all motorcycles | http://localhost:3001/motorcycles |
| `GET` | List a motorcycle based on its _id | http://localhost:3001/motorcycles/:id |
| `PUT` | Update a motorcycle based on its _id | http://localhost:3001/motorcycles/:id |
| `DELETE` | Delete a motorcycle based on its _id | http://localhost:3001/motorcycles/:id |
#### The `POST` and `PUT` endpoints require a JSON object in the following format:
```JavaScript
{
model: "Honda Biz",
year: 2022,
color: "red",
buyValue: 3500,
status: false,
category: "Street",
engineCapacity: 125
}
```
- About the properties of the above object, it is important to know:
```JavaScript
{
model: String with at least 3 characters
year: Number greater than or equal to 1900 and less than or equal to 2022
color: String with at least 3 characters
buyValue: Integer
status: Optional property, indicates whether or not the motorcycle can be purchased (boolean)
category: String that only accepts the values Street, Custom or Trail
engineCapacity: Number greater than 0 and less than or equal to 2500
}
```