To get started, clone or download the NestJS application from the repository. Once you've got the code locally, navigate to the project directory in your terminal and run:
npm install
This command installs all the necessary dependencies for the NestJS application.
After installing the dependencies, you can start the application by running:
npm run start
Your NestJS application has two main routes for user
registration and authentication:
- Signup Route (
POST /api/auth/signup
): This route registers a new user. - Login Route (
POST /api/auth/login
): This route allows users to log in.
To create a new user, you'll send a POST
request to /api/auth/signup
with the required user information (e.g., firstName
, lastName
, email
, password
). The request body should adhere to the NewUserDto
structure defined in user.dto
.
curl -X POST http://localhost:3000/api/auth/signup -H "Content-Type: application/json" -d '{
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"password": "mysecretpassword"
}'
{
"success": true/false,
"message": "Signup success"
}
For user login, send a POST
request to /api/auth/login
with the user's email
and password
in the request body (following the structure defined in LoginPayload
). Upon successful login, the route responds with a LoginResponseDto
containing a bearer_token
.
curl -X POST http://localhost:3000/api/auth/login -H "Content-Type: application/json" -d '{
"email": "[email protected]",
"password": "mysecretpassword"
}'
{
success: true,
message: 'Login success',
bearer_token: token,
}
To create a new note, send a POST
request to /api/notes
with the required note information (e.g., title
, content
). The request body should adhere to the NotesDto
structure defined in note.dto
.
curl -X POST http://localhost:3000/api/notes \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <bearer_token>" \
-d '{
"title": "New Note Title",
"content": "This is the content of the note"
}'
{
"data": {
"_id": "6595a3e3311e84e63b5cc236",
"title": "New Note Title",
"content": "This is the content of the note",
"adminUserIds": ["userId"],
"createdAt": "2024-01-03T18:13:55.101Z",
"updatedAt": "2024-01-03T18:13:55.101Z"
}
}
To update an existing note, send a PUT
request to /api/notes/:id
with the note ID as a route parameter and the updated note information in the request body. The request body should adhere to the NotesDto
structure defined in note.dto
.
curl -X PUT http://localhost:3000/api/notes/:id \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <bearer_token>" \
-d '{
"title": "Updated Note Title",
"content": "This is the updated content of the note"
}'
{
"data": {
"_id": "6595a3e3311e84e63b5cc236",
"title": "Updated Note Title",
"content": "This is the updated content of the note",
"adminUserIds": ["userId"],
"createdAt": "2024-01-03T18:13:55.101Z",
"updatedAt": "2024-01-04T08:00:00.000Z"
}
}
To retrieve a specific note, send a GET
request to /api/notes/:id
with the note ID as a route parameter. This endpoint requires authorization.
curl -X GET http://localhost:3000/api/notes/:id \
-H "Authorization: Bearer <bearer_token>"
{
"data": {
"_id": "6595a3e3311e84e63b5cc236",
"title": "Note Title",
"content": "This is the content of the note",
"adminUserIds": ["userId"],
"createdAt": "2024-01-03T18:13:55.101Z",
"updatedAt": "2024-01-03T18:13:55.101Z"
}
}
To retrieve all notes, send a GET
request to /api/notes
. This endpoint requires authorization.
curl -X GET http://localhost:3000/api/notes \
-H "Authorization: Bearer <bearer_token>"
{
"data": [
{
"_id": "6595a3e3311e84e63b5cc236",
"title": "Note Title 1",
"content": "This is the content of note 1",
"adminUserIds": ["userId"],
"createdAt": "2024-01-03T18:13:55.101Z",
"updatedAt": "2024-01-03T18:13:55.101Z"
},
{
"_id": "7595a3e3311e84e63b5cc237",
"title": "Note Title 2",
"content": "This is the content of note 2",
"adminUserIds": ["userId"],
"createdAt": "2024-01-04T10:00:00.000Z",
"updatedAt": "2024-01-04T10:00:00.000Z"
}
]
}
To delete a specific note, send a DELETE
request to /api/notes/:id
with the note ID as a route parameter. This endpoint requires authorization.
curl -X DELETE http://localhost:3000/api/notes/:id \
-H "Authorization: Bearer <bearer_token>"
{
"success": true
}
To share a specific note, send a POST
request to /api/notes/:id/share
with the note ID as a route parameter. This endpoint generates a sharing URL for the note. This endpoint requires authorization.
curl -X POST http://localhost:3000/api/notes/:id/share \
-H "Authorization: Bearer <bearer_token>"
{
"sharingUrl": "https://localhost:3000/api/notes/:id/share?token=<share_token>"
}
To access a shared note via a sharing URL, send a GET
request to /api/notes/:id/share
. This endpoint allows access to the shared note if the token is valid.
curl -X GET http://localhost:3000/api/notes/:id/share?token=<share_token>
{
"data": {
"_id": "6595a3e3311e84e63b5cc236",
"title": "Shared Note Title",
"content": "Content of the shared note",
"adminUserIds": ["sharedUserId"],
"createdAt": "2024-01-03T18:13:55.101Z",
"updatedAt": "2024-01-03T18:13:55.101Z"
}
}