Skip to content

Commit e7a7723

Browse files
authored
Merge pull request #1 from oreyon/main
Add nest/swagger API documentation
2 parents fe3ce40 + c5a2b34 commit e7a7723

16 files changed

+270
-28
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
33
</p>
44

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-
85
<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>
96
<p align="center">
107
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
@@ -27,7 +24,9 @@
2724
My Learning Project in Nest.JS, Creating Simple Contact API
2825

2926
## Project Checklist
27+
3028
### User Endpoint
29+
3130
- [x] Register User
3231
- [x] Send Email to Verify User
3332
- [x] Verify User
@@ -38,6 +37,7 @@ My Learning Project in Nest.JS, Creating Simple Contact API
3837
- [x] Logout User
3938

4039
### Contact Endpoint
40+
4141
- [x] Get All Contact & Search Contact
4242
- [x] Create Contact
4343
- [x] Get Contact
@@ -46,26 +46,31 @@ My Learning Project in Nest.JS, Creating Simple Contact API
4646
- [x] Delete Contact
4747

4848
### Address Endpoint
49+
4950
- [x] Get All Addresses in the Contact
5051
- [x] Create Addresses of Contact
5152
- [x] Get Address
5253
- [x] Update Address
5354
- [x] Delete Address
5455

55-
5656
### Todo
57+
5758
- [ ] Make Endpoint for forgot password
58-
- [ ] Setup Swagger UI
59-
- [ ] Create setup for multer to upload in cloud bucket like Cloudflare R2, AWS S3, or GCP Cloud Storage
59+
- [x] Setup Swagger UI
60+
- [ ] Create setup for multer to upload in cloud bucket like Cloudflare R2, AWS S3, or GCP Cloud Storage
6061

6162
## Project Endpoint
63+
6264
You can see at **doc** folder or import the postman collection.
65+
or you can go to swagger api docs:
66+
67+
[SWAGGER API DOCS](https://localhost:3000/api)
6368

6469
## Project setup
6570

6671
```bash
67-
$ npm install
68-
$ npx prisma init
72+
npm install
73+
npx prisma init
6974
```
7075

7176
## Setup your .env
@@ -87,7 +92,7 @@ HASHIDS_SALT=YOURSALT
8792
## Run Prisma
8893

8994
```bash
90-
$ npx prisma migrate dev
95+
npx prisma migrate dev
9196
```
9297

9398
## Compile and run the project
@@ -111,7 +116,9 @@ $ npm run test
111116
```
112117

113118
## Another way to Run
119+
114120
More simple shortcut to use in windows :D
121+
115122
```bash
116123
run.bat dev|test|build|lint|prod
117124
```
@@ -123,8 +130,8 @@ When you're ready to deploy your NestJS application to production, there are som
123130
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:
124131

125132
```bash
126-
$ npm install -g mau
127-
$ mau deploy
133+
npm install -g mau
134+
mau deploy
128135
```
129136

130137
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@nestjs/config": "^3.3.0",
2424
"@nestjs/core": "^10.0.0",
2525
"@nestjs/platform-express": "^10.0.0",
26+
"@nestjs/swagger": "^8.0.7",
2627
"@nestjs/throttler": "^6.2.1",
2728
"@prisma/client": "^5.22.0",
2829
"bcrypt": "^5.1.1",

src/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import { UserModule } from './user/user.module';
44
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
55
import { ContactModule } from './contact/contact.module';
66
import { AddressModule } from './address/address.module';
7+
import { ConfigModule } from '@nestjs/config';
78

89
@Module({
910
imports: [
11+
ConfigModule.forRoot({
12+
isGlobal: true,
13+
}),
1014
ThrottlerModule.forRoot({
1115
throttlers: [
1216
{

src/common/common.module.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Global, MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
2-
import { ConfigModule } from '@nestjs/config';
32
import { WinstonModule } from 'nest-winston';
43
import * as winston from 'winston';
54
import { PrismaService } from './prisma.service';
@@ -28,9 +27,6 @@ import { MulterService } from './multer.service';
2827
}),
2928
],
3029
}),
31-
ConfigModule.forRoot({
32-
isGlobal: true,
33-
}),
3430
],
3531
controllers: [],
3632
providers: [

src/common/mail.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ export class MailService {
1414
this.transporter = nodemailer.createTransport({
1515
host: this.configService.get<string>('MAIL_HOST'),
1616
port: this.configService.get<number>('MAIL_PORT'),
17-
secure: this.configService.get<boolean>('MAIL_SECURE'),
1817
auth: {
1918
user: this.configService.get<string>('MAIL_USER'),
2019
pass: this.configService.get<string>('MAIL_PASS'),
2120
},
21+
debug: false,
22+
logger: false,
2223
} as SMTPTransport.Options);
2324
}
2425

src/contact/contact.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import { User } from '@prisma/client';
3030
import { MulterService } from '../common/multer.service';
3131
import { MulterInterceptor } from '../common/multer.interceptor';
3232
import { Request } from 'express';
33+
import { ApiBearerAuth } from '@nestjs/swagger';
3334

35+
@ApiBearerAuth()
3436
@Controller('/api/contacts')
3537
export class ContactController {
3638
constructor(

src/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AppModule } from './app.module';
33
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
44
import { NestExpressApplication } from '@nestjs/platform-express';
55
import { join } from 'path';
6+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
67

78
async function bootstrap() {
89
const app = await NestFactory.create<NestExpressApplication>(AppModule);
@@ -11,6 +12,16 @@ async function bootstrap() {
1112
prefix: '/uploads',
1213
});
1314

15+
const config = new DocumentBuilder()
16+
.setTitle('Contact App API')
17+
.setDescription('Contact App API')
18+
.setVersion('1.0')
19+
.addTag('Contacts')
20+
.addBearerAuth()
21+
.build();
22+
const documentFactory = () => SwaggerModule.createDocument(app, config);
23+
SwaggerModule.setup('api', app, documentFactory);
24+
1425
const logger = app.get(WINSTON_MODULE_NEST_PROVIDER);
1526
app.useLogger(logger);
1627

src/model/address.model.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
13
export class AddressRequest {
4+
@ApiProperty({
5+
example: 'Jl. Kenangan',
6+
})
27
street: string;
8+
9+
@ApiProperty({
10+
example: 'Jakarta',
11+
})
312
city: string;
13+
14+
@ApiProperty({
15+
example: 'DKI Jakarta',
16+
})
417
province: string;
18+
19+
@ApiProperty({
20+
example: 'Indonesia',
21+
})
522
country: string;
23+
24+
@ApiProperty({
25+
example: '12345',
26+
})
627
postalCode: string;
28+
29+
@ApiProperty({
30+
example: 'Yang ada di depan rumah',
31+
})
732
detail?: string;
833
}
934

@@ -18,10 +43,26 @@ export class AddressResponse {
1843
}
1944

2045
export class AddressUpdateRequest {
46+
@ApiProperty({
47+
example: '1840 Democracy Point',
48+
})
2149
street?: string;
50+
51+
@ApiProperty({
52+
example: 'Colorado Springs',
53+
})
2254
city?: string;
55+
56+
@ApiProperty({
57+
example: 'Colorado',
58+
})
2359
province?: string;
60+
61+
@ApiProperty({
62+
example: 'United States',
63+
})
2464
country?: string;
65+
2566
postalCode?: string;
2667
detail?: string;
2768
}

0 commit comments

Comments
 (0)