Skip to content

Commit 1227d64

Browse files
committed
feat(examples): with-nest added delete method
1 parent 072ab09 commit 1227d64

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

examples/with-nest/src/app.controller.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
1+
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'
22
import { UsersService } from './app.service'
33
import { CreateUserDto } from './dto/users.dto'
44

@@ -21,12 +21,7 @@ export class UsersController {
2121
await this.usersService.add(user)
2222
}
2323

24-
@Post('reset')
25-
async resetUsers() {
26-
await this.usersService.reset()
27-
}
28-
29-
@Post('remove/:id')
24+
@Delete(':id')
3025
async removeUser(@Param('id') id: string) {
3126
await this.usersService.remove(Number(id))
3227
}

examples/with-nest/src/app.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ export class UsersService implements OnModuleInit {
2626
this.usersProvider.data.users = users
2727
}
2828

29-
async reset(): Promise<void> {
30-
await this.usersProvider.reset()
31-
}
32-
3329
findById(id: number): CreateUserDto {
3430
return this.users.find((user) => user.id === id)
3531
}

examples/with-nest/src/dto/users.dto.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Exclude, Type } from 'class-transformer'
2-
import { Length, Max, Min } from 'class-validator'
2+
import { IsNumber, IsString, Length, Max, Min } from 'class-validator'
33

44
export class Users {
55
@Type(() => CreateUserDto)
@@ -11,12 +11,15 @@ export class Users {
1111
}
1212

1313
export class CreateUserDto {
14+
@IsNumber()
1415
@Exclude({ toPlainOnly: true })
1516
id: number
1617

18+
@IsString()
1719
@Length(1, 20)
1820
name: string
1921

22+
@IsNumber()
2023
@Min(12)
2124
@Max(100)
2225
age: number

0 commit comments

Comments
 (0)