Skip to content

Commit 7666c38

Browse files
feat(todos): implement protected CRUD for user-specific todos
1 parent ae6ed1c commit 7666c38

23 files changed

+479
-139
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ DATABASE_URL="mongodb://localhost:27017/db"
22
PORT=3000
33
HOST="localhost"
44
SWAGGER_ROOT="/docs"
5-
JWT_SECRET="YOUR_SUPER_SECRET_KEY"
5+
JWT_SECRET="YOUR_SUPER_SECRET_KEY" # Replace with your actual secret key
66
JWT_EXPIRES_IN="1h"

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:18-alpine
2+
WORKDIR /app
3+
COPY --from=builder /app/package*.json ./
4+
RUN npm install --only=production
5+
COPY --from=builder /app/dist ./dist
6+
COPY --from=builder /app/prisma ./prisma
7+
EXPOSE 3000
8+
CMD ["node", "dist/main"]

README.md

Lines changed: 56 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,79 @@
1-
<p align="center">
2-
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3-
</p>
4-
5-
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6-
[circleci-url]: https://circleci.com/gh/nestjs/nest
7-
8-
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9-
<p align="center">
10-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13-
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
15-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
16-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
17-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
18-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
19-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
20-
</p>
21-
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
22-
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
23-
24-
## Description
25-
26-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
27-
28-
## Project setup
1+
# NestJS Todo API
292

30-
```bash
31-
$ npm install
32-
```
3+
A RESTful API for a simple todo list manager, built with NestJS, TypeScript, and Prisma. This project serves as a demonstration of modern backend development practices, including JWT authentication, robust validation, and a clean, modular architecture.
334

34-
## Compile and run the project
5+
![Alt Text](nest.png)
356

36-
```bash
37-
# development
38-
$ npm run start
7+
---
398

40-
# watch mode
41-
$ npm run start:dev
9+
## Features
4210

43-
# production mode
44-
$ npm run start:prod
45-
```
11+
- **JWT-based Authentication**: Secure user registration and login endpoints.
12+
- **Protected Routes**: All todo-related endpoints require a valid access token.
13+
- **Full CRUD Functionality**: Create, Read, Update, and Delete operations for user-specific todos.
14+
- **Validation**: DTO-based validation for all incoming request bodies using `class-validator`.
15+
- **API Documentation**: Auto-generated and detailed API documentation with Swagger.
4616

47-
## Run tests
17+
---
4818

49-
```bash
50-
# unit tests
51-
$ npm run test
19+
## Tech Stack
5220

53-
# e2e tests
54-
$ npm run test:e2e
21+
- **Framework**: [NestJS](https://nestjs.com/)
22+
- **Language**: [TypeScript](https://www.typescriptlang.org/)
23+
- **ORM**: [Prisma](https://www.prisma.io/)
24+
- **Database**: [MongoDB](https://www.mongodb.com/)
25+
- **Authentication**: [JWT](https://jwt.io/) with [Passport.js](http://www.passportjs.org/)
26+
- **Validation**: [class-validator](https://github.com/typestack/class-validator) & [class-transformer](https://github.com/typestack/class-transformer)
5527

56-
# test coverage
57-
$ npm run test:cov
58-
```
28+
---
5929

60-
## Deployment
30+
## Getting Started
6131

62-
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
32+
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
6333

64-
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
34+
### Prerequisites
6535

66-
```bash
67-
$ npm install -g @nestjs/mau
68-
$ mau deploy
69-
```
36+
- [Node.js](https://nodejs.org/en/) (v18 or later recommended)
37+
- [npm](https://www.npmjs.com/)
38+
- A running [MongoDB](https://www.mongodb.com/try/download/community) instance (must be running as a replica set for Prisma transactions).
7039

71-
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
40+
### Installation & Setup
7241

73-
## Resources
42+
1. **Clone the repository:**
43+
```bash
44+
git clone https://github.com/mohammadhasanii/NestTodo-API.git
45+
```
7446

75-
Check out a few resources that may come in handy when working with NestJS:
47+
2. **Navigate to the project directory:**
48+
```bash
49+
cd NestTodo-API
50+
```
7651

77-
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
78-
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
79-
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
80-
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
81-
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
82-
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
83-
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
84-
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
52+
3. **Install dependencies:**
53+
```bash
54+
npm install
55+
```
8556

86-
## Support
57+
4. **Configure environment variables:**
58+
Create a `.env` file in the root of the project by copying the example file:
59+
```bash
60+
cp .env.example .env
61+
```
62+
Then, update the `.env` file with your specific configuration.
8763

88-
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
64+
```env
65+
# The connection string for your MongoDB instance.
66+
# Note: ?replicaSet=rs0 is required if your MongoDB is running as a replica set.
67+
DATABASE_URL="mongodb://localhost:27017/db?replicaSet=rs0"
8968
90-
## Stay in touch
69+
# A strong, secret key for signing JWTs
70+
JWT_SECRET="YOUR_SUPER_SECRET_KEY"
71+
JWT_EXPIRES_IN="1h"
72+
```
9173

92-
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
93-
- Website - [https://nestjs.com](https://nestjs.com/)
94-
- Twitter - [@nestframework](https://twitter.com/nestframework)
74+
### Running the Application
9575

96-
## License
76+
To run the application in development mode with hot-reloading:
9777

98-
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
78+
```bash
79+
npm run start:dev

nest.png

715 KB
Loading

package-lock.json

Lines changed: 98 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
"type": "git",
55
"url": "https://github.com/mohammadhasanii/NestTodo-API.git"
66
},
7-
"version": "1.0.0",
7+
"version": "1.1.0",
88
"description": "",
99
"author": "",
1010
"private": true,
1111
"license": "UNLICENSED",
12+
"prisma": {
13+
"seed": "ts-node prisma/seed.ts"
14+
},
1215
"scripts": {
1316
"build": "nest build",
1417
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
@@ -28,12 +31,15 @@
2831
"@nestjs/config": "^4.0.2",
2932
"@nestjs/core": "^11.0.1",
3033
"@nestjs/jwt": "^11.0.0",
34+
"@nestjs/passport": "^11.0.5",
3135
"@nestjs/platform-express": "^11.0.1",
3236
"@nestjs/swagger": "^11.2.0",
3337
"@prisma/client": "^6.12.0",
3438
"bcrypt": "^6.0.0",
3539
"class-transformer": "^0.5.1",
3640
"class-validator": "^0.14.2",
41+
"passport": "^0.7.0",
42+
"passport-jwt": "^4.0.1",
3743
"reflect-metadata": "^0.2.2",
3844
"rxjs": "^7.8.1"
3945
},
@@ -49,6 +55,7 @@
4955
"@types/express": "^5.0.0",
5056
"@types/jest": "^29.5.14",
5157
"@types/node": "^22.10.7",
58+
"@types/passport-jwt": "^4.0.1",
5259
"@types/supertest": "^6.0.2",
5360
"eslint": "^9.18.0",
5461
"eslint-config-prettier": "^10.0.1",
@@ -82,4 +89,4 @@
8289
"coverageDirectory": "../coverage",
8390
"testEnvironment": "node"
8491
}
85-
}
92+
}

0 commit comments

Comments
 (0)