-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed the Basic CRUD API using NestJS , It was a great learning e…
…xperience. Signed-off-by: Animesh Raj <[email protected]>
- Loading branch information
0 parents
commit cbb6d37
Showing
22 changed files
with
10,137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.