This API provides endpoints to manage users, their profiles, and posts.
I followed YouTube Tutorial 'NestJS, MySQL, TypeORM Crash Course' by Anson the Developer.
- Node.js (>=12.x)
- npm (>=6.x)
- Nest.js (>=8.x)
- MySQL Database
-
Clone the repository:
git clone https://github.com/tirthacodes/nest-js-third.git
-
Install dependencies:
cd nest-js-third npm install
-
Set up the MySQL database:
- Make sure you have MySQL installed.
- Create a new database named
nestjs_mysql_tutorial
.
-
Configure the database connection:
- Open
src/app.module.ts
. - Update the database connection details under the
TypeOrmModule.forRoot()
options. - Ensure the
entities
array includes theUser
,Profile
, andPost
entities.
- Open
-
Run the application:
npm run start:dev
- GET /users: Get all users, their profiles, and posts.
- POST /users: Create a new user.
- PUT /users/:id: Update a user by ID.
- DELETE /users/:id: Delete a user by ID.
- POST /users/:id/profiles: Create a profile for a user by ID.
- POST /users/:id/posts: Create a post for a user by ID.
- Method: POST
- URL:
/users
- Body:
{ "username": "newuser", "password": "newpassword" }
- Response:
{ "id": 1, "username": "newuser", "createdAt": "2023-08-10T12:34:56.789Z" }
- Method: PUT
- URL:
/users/:id
- Body:
{ "username": "updateduser", "password": "updatedpassword" }
- Response:
{ "id": 1, "username": "updateduser", "createdAt": "2023-08-10T12:34:56.789Z" }
Contributions are welcome! Feel free to open issues or submit pull requests for improvements, bug fixes, or new features.