This project is a simple REST API for user management using NestJS, Sequelize, and JWT.
POST /api/v1/add-user
Creates a new user and saves it to the database.
Request:
-
Content-Type:
application/json -
Request Body:
{ "name": "John Doe", "email": "[email protected]", "phone": "1234567890", "password": "yourpassword" // Required for registration }
Response:
-
Status:
201 Created -
Response Body:
{ "id": 1, "name": "John Doe", "email": "[email protected]", "phone": "1234567890", "createdAt": "2024-08-16T00:00:00.000Z", "updatedAt": "2024-08-16T00:00:00.000Z" }
GET /api/v1/get-user/:id
Retrieves user information based on the specified ID.
Authorization:
- Header:
Authorization: Bearer <your-token> - Description: A valid JWT token is required in the
Authorizationheader to access this endpoint.
Query Parameters:
id(URL parameter) — User ID.
Response:
-
Status:
200 OK -
Response Body:
{ "id": 1, "name": "John Doe", "email": "[email protected]", "phone": "1234567890", "createdAt": "2024-08-16T00:00:00.000Z", "updatedAt": "2024-08-16T00:00:00.000Z" } -
Status:
401 Unauthorized(if no token or an invalid token is provided) -
Response Body:
{ "statusCode": 401, "message": "Unauthorized", "error": "Unauthorized" } -
Status:
404 Not Found(if the user with the specified ID is not found) -
Response Body:
{ "statusCode": 404, "message": "Not Found", "error": "Not Found" }
POST /api/v1/login
Allows users to log in and receive a JWT token.
Request:
-
Content-Type:
application/json -
Request Body:
{ "email": "[email protected]", "password": "yourpassword" }
Response:
-
Status:
200 OK -
Response Body:
{ "accessToken": "your.jwt.token.here" }
To access protected routes, you need to pass the JWT token in the Authorization header in the format Bearer <your-token>.
Example Header:
Authorization: Bearer your.jwt.token.here-
Clone the repository:
git clone https://github.com/yourusername/your-repo-name.git
-
Install dependencies:
cd your-repo-name npm install -
Start the project:
npm run start
To run database migrations, use:
npm run migrate