Skip to content

Commit

Permalink
Completed the Basic CRUD API using NestJS , It was a great learning e…
Browse files Browse the repository at this point in the history
…xperience.

Signed-off-by: Animesh Raj <[email protected]>
  • Loading branch information
itsarraj committed Jul 3, 2024
0 parents commit cbb6d37
Show file tree
Hide file tree
Showing 22 changed files with 10,137 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
117 changes: 117 additions & 0 deletions Description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# To-Do List Management API Documentation

## Overview

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.

## Code Structure

### Source Directory (`src`)
- __`app.controller.ts`__: Controller for handling incoming requests to the root endpoint.
- __`app.controller.spec.ts`__: Unit tests for `app.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.

### Test Directory (`test`)
- __`app.controller.e2e-spec.ts`__: End-to-end tests for the `AppController`.
- __`tasks.controller.e2e-spec.ts`__: End-to-end tests for the `TasksController`.
- __`jest-e2e.json`__: Configuration for end-to-end testing with Jest.

## Key Decisions

1. __NestJS Framework__: Chosen for its modular architecture, built-in dependency injection, and powerful CLI.
2. __Mongoose__: Used for MongoDB object modeling, providing schema-based solutions for application data.
3. __Modular Structure__: Organized code into modules (e.g., `tasks` module) to enhance maintainability and scalability.
4. __Testing__: Included both unit and end-to-end tests to ensure code quality and reliability.
5. __Environment Variables__: Used environment variables to store sensitive information such as MongoDB connection strings.

## API Endpoints

### Task Endpoints

#### Get All Tasks
- __URL__: `/tasks`
- __Method__: GET
- __Description__: Retrieves all tasks from the database.
- __Response__: Array of Task objects.

#### Create a Task
- __URL__: `/tasks`
- __Method__: POST
- __Description__: Creates a new task.
- __Request Body__:
```json
{
"title": "Task Title",
"planning": "Task Planning",
"done": false
}
```
- __Response__: The created Task object.

#### Update a Task
- __URL__: `/tasks/:id`
- __Method__: PUT
- __Description__: Updates an existing task by ID.
- __Request Body__:
```json
{
"title": "Updated Task Title",
"planning": "Updated Task Planning",
"done": false
}
```
- __Response__: The updated Task object.

#### Delete a Task
- __URL__: `/tasks/:id`
- __Method__: DELETE
- __Description__: Deletes a task by ID.
- __Response__: The deleted Task object.

#### Mark a Task as Done
- __URL__: `/tasks/:id/done`
- __Method__: PATCH
- __Description__: Marks a task as completed by ID.
- __Response__: The updated Task object with `done` set to `true`.

## Running the Application

### Prerequisites
- Node.js and npm
- MongoDB instance

### Installation
1. Clone the repository:
```bash
git clone https://github.com/itsarraj/todo-api-nestjs.git
```
2. Install dependencies:
```bash
cd todo-api-nestjs
npm install
```

### Running the Application
1. Start the NestJS application:
```bash
npm run start
```
2. The application will be running at `http://localhost:3000`.

### Running Tests
- Unit tests:
```bash
npm run test
```
- End-to-end tests:
```bash
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.
Binary file added Description.md.pdf
Binary file not shown.
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# To-Do List Management API Documentation

## Overview

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.

## Code Structure

### Source Directory (`src`)

- **`app.controller.ts`**: Controller for handling incoming requests to the root endpoint.
- **`app.controller.spec.ts`**: Unit tests for `app.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.

### Test Directory (`test`)

- **`app.controller.e2e-spec.ts`**: End-to-end tests for the `AppController`.
- **`tasks.controller.e2e-spec.ts`**: End-to-end tests for the `TasksController`.
- **`jest-e2e.json`**: Configuration for end-to-end testing with Jest.

## Key Decisions

1. **NestJS Framework**: Chosen for its modular architecture, built-in dependency injection, and powerful CLI.
2. **Mongoose**: Used for MongoDB object modeling, providing schema-based solutions for application data.
3. **Modular Structure**: Organized code into modules (e.g., `tasks` module) to enhance maintainability and scalability.
4. **Testing**: Included both unit and end-to-end tests to ensure code quality and reliability.
5. **Environment Variables**: Used environment variables to store sensitive information such as MongoDB connection strings.

## API Endpoints

### Task Endpoints

#### Get All Tasks

- **URL**: `/tasks`
- **Method**: GET
- **Description**: Retrieves all tasks from the database.
- **Response**: Array of Task objects.

#### Create a Task

- **URL**: `/tasks`
- **Method**: POST
- **Description**: Creates a new task.
- **Request Body**:
```json
{
"title": "Task Title",
"planning": "Task Planning",
"done": false
}
```
- **Response**: The created Task object.

#### Update a Task

- **URL**: `/tasks/:id`
- **Method**: PUT
- **Description**: Updates an existing task by ID.
- **Request Body**:
```json
{
"title": "Updated Task Title",
"planning": "Updated Task Planning",
"done": false
}
```
- **Response**: The updated Task object.

#### Delete a Task

- **URL**: `/tasks/:id`
- **Method**: DELETE
- **Description**: Deletes a task by ID.
- **Response**: The deleted Task object.

#### Mark a Task as Done

- **URL**: `/tasks/:id/done`
- **Method**: PATCH
- **Description**: Marks a task as completed by ID.
- **Response**: The updated Task object with `done` set to `true`.

## Running the Application

### Prerequisites

- Node.js and npm
- MongoDB instance

### Installation

1. Clone the repository:
```bash
git clone https://github.com/itsarraj/todo-api-nestjs.git
```
2. Install dependencies:
```bash
cd todo-api-nestjs
npm install
```

### Running the Application

1. Start the NestJS application:
```bash
npm run start
```
2. The application will be running at `http://localhost:3000`.

### Running Tests

- Unit tests:
```bash
npm run test
```
- End-to-end tests:
```bash
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.
8 changes: 8 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading

0 comments on commit cbb6d37

Please sign in to comment.