This API provides endpoints for managing a to-do list, including functionalities for adding, editing, deleting tasks, marking tasks as completed, and retrieving tasks. It is built using NestJS and MongoDB with Mongoose for data storage.
app.controller.ts
: Controller for handling incoming requests to the root endpoint.app.controller.spec.ts
: Unit tests forapp.controller.ts
.app.module.ts
: Main module for the application, imports other modules.app.service.ts
: Provides services to the controller.main.ts
: Entry point of the application.tasks/
: Directory containing task-related modules, controllers, and services.task.model.ts
: Mongoose schema and interface for the Task model.tasks.controller.ts
: Controller for handling task-related requests.tasks.service.ts
: Provides task-related business logic.
app.controller.e2e-spec.ts
: End-to-end tests for theAppController
.tasks.controller.e2e-spec.ts
: End-to-end tests for theTasksController
.jest-e2e.json
: Configuration for end-to-end testing with Jest.
- NestJS Framework: Chosen for its modular architecture, built-in dependency injection, and powerful CLI.
- Mongoose: Used for MongoDB object modeling, providing schema-based solutions for application data.
- Modular Structure: Organized code into modules (e.g.,
tasks
module) to enhance maintainability and scalability. - Testing: Included both unit and end-to-end tests to ensure code quality and reliability.
- Environment Variables: Used environment variables to store sensitive information such as MongoDB connection strings.
- URL:
/tasks
- Method: GET
- Description: Retrieves all tasks from the database.
- Response: Array of Task objects.
- URL:
/tasks
- Method: POST
- Description: Creates a new task.
- Request Body:
{ "title": "Task Title", "planning": "Task Planning", "done": false }
- Response: The created Task object.
- URL:
/tasks/:id
- Method: PUT
- Description: Updates an existing task by ID.
- Request Body:
{ "title": "Updated Task Title", "planning": "Updated Task Planning", "done": false }
- Response: The updated Task object.
- URL:
/tasks/:id
- Method: DELETE
- Description: Deletes a task by ID.
- Response: The deleted Task object.
- URL:
/tasks/:id/done
- Method: PATCH
- Description: Marks a task as completed by ID.
- Response: The updated Task object with
done
set totrue
.
- Node.js and npm
- MongoDB instance
- Clone the repository:
git clone https://github.com/itsarraj/todo-api-nestjs.git
- Install dependencies:
cd todo-api-nestjs npm install
- Start the NestJS application:
npm run start
- The application will be running at
http://localhost:3000
.
- Unit tests:
npm run test
- End-to-end tests:
npm run test:e2e
This documentation provides an overview of the code structure, key decisions, and API endpoints for the To-Do List Management API built with NestJS. For further details, refer to the code comments and the respective modules.