Skip to content

Commit b5ab1c4

Browse files
committed
feat: add req body validation & swagger docs to shelter managers routes
1 parent d202126 commit b5ab1c4

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsNotEmpty, IsString } from 'class-validator';
3+
4+
export class CreateShelterManagerDTO {
5+
@ApiProperty({ type: 'string', example: 'ID do Abrigo' })
6+
@IsNotEmpty()
7+
@IsString()
8+
readonly shelterId = '';
9+
10+
@ApiProperty({ type: 'string', example: 'ID do Usuário' })
11+
@IsNotEmpty()
12+
@IsString()
13+
readonly userId = '';
14+
}

src/shelter-managers/shelter-managers.controller.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ import {
99
Query,
1010
UseGuards,
1111
} from '@nestjs/common';
12-
import { ApiTags } from '@nestjs/swagger';
12+
import {
13+
ApiBadRequestResponse,
14+
ApiBearerAuth,
15+
ApiInternalServerErrorResponse,
16+
ApiOkResponse,
17+
ApiTags,
18+
ApiUnauthorizedResponse,
19+
} from '@nestjs/swagger';
1320

1421
import { ShelterManagersService } from './shelter-managers.service';
1522
import { ServerResponse } from '../utils';
1623
import { AdminGuard } from '@/guards/admin.guard';
24+
import { CreateShelterManagerDTO } from './dtos/CreateShelterManagerDTO';
1725

1826
@ApiTags('Admin de Abrigo')
27+
@ApiInternalServerErrorResponse()
1928
@Controller('shelter/managers')
2029
export class ShelterManagersController {
2130
private logger = new Logger(ShelterManagersController.name);
@@ -24,9 +33,13 @@ export class ShelterManagersController {
2433
private readonly shelterManagerServices: ShelterManagersService,
2534
) {}
2635

36+
@ApiBearerAuth()
37+
@ApiUnauthorizedResponse()
38+
@ApiBadRequestResponse()
39+
@ApiOkResponse()
2740
@Post('')
2841
@UseGuards(AdminGuard)
29-
async store(@Body() body) {
42+
async store(@Body() body: CreateShelterManagerDTO) {
3043
try {
3144
await this.shelterManagerServices.store(body);
3245
return new ServerResponse(200, 'Successfully added manager to shelter');
@@ -36,6 +49,7 @@ export class ShelterManagersController {
3649
}
3750
}
3851

52+
@ApiOkResponse()
3953
@Get(':shelterId')
4054
async index(
4155
@Param('shelterId') shelterId: string,

src/shelter-managers/shelter-managers.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { z } from 'zod';
21
import { Injectable } from '@nestjs/common';
32

43
import { PrismaService } from '../prisma/prisma.service';
54
import { CreateShelterManagerSchema } from './types';
5+
import { CreateShelterManagerDTO } from './dtos/CreateShelterManagerDTO';
66

77
@Injectable()
88
export class ShelterManagersService {
99
constructor(private readonly prismaService: PrismaService) {}
1010

11-
async store(body: z.infer<typeof CreateShelterManagerSchema>) {
11+
async store(body: CreateShelterManagerDTO) {
1212
const { shelterId, userId } = CreateShelterManagerSchema.parse(body);
1313
await this.prismaService.shelterManagers.create({
1414
data: {

0 commit comments

Comments
 (0)