@@ -10,23 +10,36 @@ import {
10
10
Query ,
11
11
UseGuards ,
12
12
} from '@nestjs/common' ;
13
- import { ApiTags } from '@nestjs/swagger' ;
13
+ import {
14
+ ApiBadRequestResponse ,
15
+ ApiBearerAuth ,
16
+ ApiInternalServerErrorResponse ,
17
+ ApiOkResponse ,
18
+ ApiTags ,
19
+ ApiUnauthorizedResponse ,
20
+ } from '@nestjs/swagger' ;
14
21
15
22
import { ShelterService } from './shelter.service' ;
16
23
import { ServerResponse } from '../utils' ;
17
24
import { StaffGuard } from '@/guards/staff.guard' ;
18
25
import { ApplyUser } from '@/guards/apply-user.guard' ;
19
26
import { UserDecorator } from '@/decorators/UserDecorator/user.decorator' ;
27
+ import { ShelterQueryDTO } from './dtos/ShelterQuerysDTO' ;
28
+ import { CreateShelterDTO } from './dtos/CreateShelterDTO' ;
29
+ import { UpdateShelterDTO } from './dtos/UpdateShelterDTO' ;
20
30
21
31
@ApiTags ( 'Abrigos' )
32
+ @ApiInternalServerErrorResponse ( )
22
33
@Controller ( 'shelters' )
23
34
export class ShelterController {
24
35
private logger = new Logger ( ShelterController . name ) ;
25
36
26
37
constructor ( private readonly shelterService : ShelterService ) { }
27
38
39
+ @ApiBadRequestResponse ( )
40
+ @ApiOkResponse ( )
28
41
@Get ( '' )
29
- async index ( @Query ( ) query ) {
42
+ async index ( @Query ( ) query : ShelterQueryDTO ) {
30
43
try {
31
44
const data = await this . shelterService . index ( query ) ;
32
45
return new ServerResponse ( 200 , 'Successfully get shelters' , data ) ;
@@ -36,6 +49,8 @@ export class ShelterController {
36
49
}
37
50
}
38
51
52
+ @ApiBadRequestResponse ( )
53
+ @ApiOkResponse ( )
39
54
@Get ( 'cities' )
40
55
async cities ( ) {
41
56
try {
@@ -47,6 +62,8 @@ export class ShelterController {
47
62
}
48
63
}
49
64
65
+ @ApiBearerAuth ( )
66
+ @ApiOkResponse ( )
50
67
@Get ( ':id' )
51
68
@UseGuards ( ApplyUser )
52
69
async show ( @UserDecorator ( ) user : any , @Param ( 'id' ) id : string ) {
@@ -61,9 +78,13 @@ export class ShelterController {
61
78
}
62
79
}
63
80
81
+ @ApiBearerAuth ( )
82
+ @ApiUnauthorizedResponse ( )
83
+ @ApiBadRequestResponse ( )
84
+ @ApiOkResponse ( )
64
85
@Post ( '' )
65
86
@UseGuards ( StaffGuard )
66
- async store ( @Body ( ) body ) {
87
+ async store ( @Body ( ) body : CreateShelterDTO ) {
67
88
try {
68
89
const data = await this . shelterService . store ( body ) ;
69
90
return new ServerResponse ( 200 , 'Successfully created shelter' , data ) ;
@@ -73,8 +94,10 @@ export class ShelterController {
73
94
}
74
95
}
75
96
97
+ @ApiBadRequestResponse ( )
98
+ @ApiOkResponse ( )
76
99
@Put ( ':id' )
77
- async update ( @Param ( 'id' ) id : string , @Body ( ) body ) {
100
+ async update ( @Param ( 'id' ) id : string , @Body ( ) body : UpdateShelterDTO ) {
78
101
try {
79
102
const data = await this . shelterService . update ( id , body ) ;
80
103
return new ServerResponse ( 200 , 'Successfully updated shelter' , data ) ;
@@ -84,9 +107,13 @@ export class ShelterController {
84
107
}
85
108
}
86
109
110
+ @ApiBearerAuth ( )
111
+ @ApiUnauthorizedResponse ( )
112
+ @ApiBadRequestResponse ( )
113
+ @ApiOkResponse ( )
87
114
@Put ( ':id/admin' )
88
115
@UseGuards ( StaffGuard )
89
- async fullUpdate ( @Param ( 'id' ) id : string , @Body ( ) body ) {
116
+ async fullUpdate ( @Param ( 'id' ) id : string , @Body ( ) body : UpdateShelterDTO ) {
90
117
try {
91
118
const data = await this . shelterService . fullUpdate ( id , body ) ;
92
119
return new ServerResponse ( 200 , 'Successfully updated shelter' , data ) ;
0 commit comments