This API is designed for user registration and authentication, allowing users to create, update, delete, and view used cars reports alongside with admin approval of each report.
- User authentication and registration using cockie session, with user-specific data retrieval.
- Full CRUD operations on reports managed by users (creation, deletion, modification, and retrieval).
- Approval feature of each report (admin functionality).
- Nest.js: a framework for building efficient, scalable Node.js web applications.
- TypeORM: an Object-Relational Mapping (ORM) library for TypeScript and JavaScript that simplifies database interaction by allowing to work with relational databases using object-oriented paradigms.
- SQLite: an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
- Jest: a popular JavaScript testing framework, designed to make testing easy, fast, and enjoyable by providing a simple and intuitive API for writing unit tests, as well as built-in support for features like mocking, snapshot testing, and code coverage analysis.
-
Clone the repository to your local machine.
-
Install dependencies using
npm install
- Create and fill
.env.development
file. Here is an example:
DB_NAME=db.sqlite
COOKIE_KEY=secret_cookie_key
APP_PORT=3000
Example for .env.test
file that is used for Test Environment:
DB_NAME=test.sqlite
COOKIE_KEY=secret_cookie_key
APP_PORT=3000
- Launch the local server using
npm run start:dev
- Run the migration to execute initial schema:
npm run typeorm migration:run -- -d ./ormconfigWrapper.js
# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:cov
Here are the routes that can be used for routing in the app.
- Method: POST
- URL: {{URL}}/auth/signup
- Data:
{
"email": "[email protected]",
"password": "password"
}
- Requires Auth: NO
- Description: This endpoint enables users to register by sending a POST request containing their chosen email and password.
- Method: POST
- URL: {{URL}}/auth/signin
- Data:
{
"email": "[email protected]",
"password": "password"
}
- Requires Auth: NO
- Description: This endpoint enables users authenticate by sending a POST request with their email and password; upon successful authentication, userId is added in session object for further private routing.
- Method: POST
- URL: {{URL}}/auth/signout
- Requires Auth: YES
- Description: This endpoint enables users log out and remove userId from session object.
- Method: GET
- URL: {{URL}}/auth/profile
- Requires Auth: YES
- Description: This endpoint retrieves the profile information of the currently authenticated user.
- Method: GET
- URL: {{URL}}/auth/:id
- Requires Auth: NO
- Description: This endpoint retrieves brief profile information of the another user.
- Method: PATCH
- URL: {{URL}}/auth/:id
- Data:
{
"email": "[email protected]",
"password": "password111"
}
- Requires Auth: YES
- Description: This endpoint allows to update user info by ID.
- Method: DELETE
- URL: {{URL}}/auth/:id
- Requires Auth: YES
- Description: This endpoint allows to delete user info by ID.
- Method: POST
- URL: {{URL}}/reports
- Data:
{
"year": 1981,
"price": 15000,
"mileage": 50000,
"lng": 45,
"lat": 45,
"model": "mustang",
"make": "ford"
}
- Requires Auth: YES
- Description: This endpoint allows authenticated users to create a new used car report with filled following fields: year, price, mileage, lng, lat, model, and make.
- Method: PATCH
- URL: {{URL}}/reports/:id
- Requires Auth: YES (Admin Only Feature)
- Description: This endpoint allows admin to approve report os the user.
- Method: GET
- URL: {{URL}}/reports/?make=ford&model=mustang&lng=45&lat=45&mileage=50000&year=1981
- Requires Auth: YES
- Description: This endpoint allows authenticated user to get estimate for existing vehicle based on parameters that user applied for search. As a result average price of vehicles is appeared. Be aware that only approved reports appear in search.