Skip to content

Commit 63437e8

Browse files
committed
feat: add req body validation & swagger docs to shelters routes
1 parent 407b3f8 commit 63437e8

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import {
3+
IsOptional,
4+
IsString,
5+
IsBoolean,
6+
IsNumber,
7+
Min,
8+
} from 'class-validator';
9+
10+
export class FullUpdateShelterDTO {
11+
@ApiProperty({ required: false, type: 'string', example: 'Nome do Abrigo' })
12+
@IsOptional()
13+
@IsString()
14+
readonly name?: string;
15+
16+
@ApiProperty({ required: false, type: 'string', example: 'PIX do Abrigo' })
17+
@IsOptional()
18+
@IsString()
19+
readonly pix?: string;
20+
21+
@ApiProperty({
22+
required: false,
23+
type: 'string',
24+
example: 'Endereço do Abrigo',
25+
})
26+
@IsOptional()
27+
@IsString()
28+
readonly address?: string;
29+
30+
@ApiProperty({ required: false, type: 'boolean', example: true })
31+
@IsOptional()
32+
@IsBoolean()
33+
readonly petFriendly?: boolean;
34+
35+
@ApiProperty({ required: false, type: 'number', example: 10 })
36+
@IsOptional()
37+
@IsNumber()
38+
@Min(0)
39+
readonly shelteredPeople?: number;
40+
41+
@ApiProperty({ required: false, type: 'number', example: 123.456 })
42+
@IsOptional()
43+
@IsNumber()
44+
readonly latitude?: number;
45+
46+
@ApiProperty({ required: false, type: 'number', example: 654.321 })
47+
@IsOptional()
48+
@IsNumber()
49+
readonly longitude?: number;
50+
51+
@ApiProperty({ required: false, type: 'number', example: 50 })
52+
@IsOptional()
53+
@IsNumber()
54+
@Min(0)
55+
readonly capacity?: number;
56+
57+
@ApiProperty({
58+
required: false,
59+
type: 'string',
60+
example: 'Contato do Abrigo',
61+
})
62+
@IsOptional()
63+
@IsString()
64+
readonly contact?: string;
65+
66+
@ApiProperty({ required: false, type: 'boolean' })
67+
@IsOptional()
68+
@IsBoolean()
69+
readonly verified?: boolean;
70+
}

src/shelter/shelter.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { UserDecorator } from '@/decorators/UserDecorator/user.decorator';
2727
import { ShelterQueryDTO } from './dtos/ShelterQuerysDTO';
2828
import { CreateShelterDTO } from './dtos/CreateShelterDTO';
2929
import { UpdateShelterDTO } from './dtos/UpdateShelterDTO';
30+
import { FullUpdateShelterDTO } from './dtos/FullUpdateShelterDTO';
3031

3132
@ApiTags('Abrigos')
3233
@ApiInternalServerErrorResponse()
@@ -113,7 +114,10 @@ export class ShelterController {
113114
@ApiOkResponse()
114115
@Put(':id/admin')
115116
@UseGuards(StaffGuard)
116-
async fullUpdate(@Param('id') id: string, @Body() body: UpdateShelterDTO) {
117+
async fullUpdate(
118+
@Param('id') id: string,
119+
@Body() body: FullUpdateShelterDTO,
120+
) {
117121
try {
118122
const data = await this.shelterService.fullUpdate(id, body);
119123
return new ServerResponse(200, 'Successfully updated shelter', data);

src/shelter/shelter.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
22
import { Prisma } from '@prisma/client';
33
import { DefaultArgs } from '@prisma/client/runtime/library';
44
import * as qs from 'qs';
5-
import { z } from 'zod';
65

76
import { PrismaService } from '../prisma/prisma.service';
87
import {
@@ -18,6 +17,7 @@ import { CreateShelterDTO } from './dtos/CreateShelterDTO';
1817
import { ShelterQueryDTO } from './dtos/ShelterQuerysDTO';
1918
import { UpdateShelterDTO } from './dtos/UpdateShelterDTO';
2019
import { ShelterSearchPropsSchema } from './types/search.types';
20+
import { FullUpdateShelterDTO } from './dtos/FullUpdateShelterDTO';
2121

2222
@Injectable()
2323
export class ShelterService {
@@ -52,7 +52,7 @@ export class ShelterService {
5252
});
5353
}
5454

55-
async fullUpdate(id: string, body: z.infer<typeof FullUpdateShelterSchema>) {
55+
async fullUpdate(id: string, body: FullUpdateShelterDTO) {
5656
const payload = FullUpdateShelterSchema.parse(body);
5757
await this.prismaService.shelter.update({
5858
where: {

0 commit comments

Comments
 (0)