-
Notifications
You must be signed in to change notification settings - Fork 293
feat: Add request body validation with DTOs & Swagger docs to the routes #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ocsoares
wants to merge
13
commits into
SOS-RS:develop
Choose a base branch
from
ocsoares:feat/add-req-body-swagger-docs-to-routes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7058145
feat: add req body validation & auth for swagger
ocsoares 819a6e5
feat: add req body validation & swagger docs to users routes
ocsoares 0d4be0f
chore: restore zod validation for users
ocsoares 9ccf1d7
feat: add req body validation & swagger docs to sessions routes
ocsoares 407b3f8
feat: add req body validation & swagger docs to shelters routes
ocsoares 63437e8
feat: add req body validation & swagger docs to shelters routes
ocsoares 3239cc7
feat: add req body validation & swagger docs to supplies routes
ocsoares 48a3e36
feat: add req body validation & swagger docs to supply-categories routes
ocsoares cefe2a4
feat: add req body validation & swagger docs to shelter managers routes
ocsoares 20572c6
feat: add req body validation & swagger docs to shelter supplies routes
ocsoares 03d9864
chore: add swagger @ApiBearerAuth in POST /users route
ocsoares a5c9f71
fix: fix ShelterQuerysDTO
ocsoares 3e68056
chore: add fields to ShelterQuerysDTO
ocsoares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class LoginSessionDTO { | ||
@ApiProperty({ type: 'string', example: 'John' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly login = ''; | ||
|
||
@ApiProperty({ type: 'string', example: 'john123' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly password = ''; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class CreateShelterManagerDTO { | ||
@ApiProperty({ type: 'string', example: 'ID do Abrigo' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly shelterId = ''; | ||
|
||
@ApiProperty({ type: 'string', example: 'ID do Usuário' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly userId = ''; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Transform } from 'class-transformer'; | ||
import { | ||
IsEnum, | ||
IsNotEmpty, | ||
IsNumber, | ||
IsOptional, | ||
IsString, | ||
Min, | ||
} from 'class-validator'; | ||
import { SupplyPriority } from 'src/supply/types'; | ||
|
||
export class CreateShelterSupplyDTO { | ||
constructor() { | ||
this.priority = SupplyPriority.UnderControl; | ||
} | ||
|
||
@ApiProperty({ type: 'string', example: 'ID do Abrigo' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly shelterId = ''; | ||
|
||
@ApiProperty({ type: 'string', example: 'ID do Suprimento' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
readonly supplyId = ''; | ||
|
||
@ApiProperty({ | ||
description: 'Prioridade de suprimento', | ||
enum: SupplyPriority, | ||
}) | ||
@IsNotEmpty() | ||
@IsEnum(SupplyPriority) | ||
@Transform((value) => Number(value.value)) | ||
readonly priority: SupplyPriority; | ||
|
||
@ApiProperty({ | ||
required: false, | ||
type: 'number', | ||
example: 1, | ||
}) | ||
@IsOptional() | ||
@IsNumber() | ||
@Min(1) | ||
@Transform((value) => Number(value.value)) | ||
readonly quantity?: number; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { ArrayMinSize, IsArray, IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class UpdateManyShelterSupplySchemaDTO { | ||
@ApiProperty({ | ||
type: [String], | ||
example: ['ID do Suprimento', 'ID do Suprimento 2'], | ||
}) | ||
@IsArray() | ||
@ArrayMinSize(1) | ||
@IsNotEmpty() | ||
@IsString({ each: true }) | ||
readonly ids!: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Transform } from 'class-transformer'; | ||
import { IsEnum, IsOptional, IsNumber, Min } from 'class-validator'; | ||
import { SupplyPriority } from 'src/supply/types'; | ||
|
||
export class UpdateShelterSupplyDTO { | ||
@ApiProperty({ | ||
required: false, | ||
description: 'Prioridade de suprimento', | ||
enum: SupplyPriority, | ||
}) | ||
@IsOptional() | ||
@IsEnum(SupplyPriority) | ||
@Transform((value) => Number(value.value)) | ||
readonly priority?: SupplyPriority; | ||
|
||
@ApiProperty({ | ||
required: false, | ||
type: 'number', | ||
example: 1, | ||
}) | ||
@IsOptional() | ||
@IsNumber() | ||
@Min(1) | ||
@Transform((value) => Number(value.value)) | ||
readonly quantity?: number; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
não deveria ser obrigatório? afinal estou criando um suprimento e estou dizendo que seu deve ser mínimo um
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu apenas segui a lógica já implementada na aplicação, então nesse DTO a propriedade "quantity" deve ser opcional, como consta nos types
backend/src/shelter-supply/types.ts
Lines 5 to 25 in c40e724
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfeito! Acredito que não era para ter esse 'estado' nos types mas como já é o formato antigo, tudo em ordem camarada