-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow null numbers and validate them correctly (#182)
* Allow null numbers and validate them correctly * Revert string number validator. Handle null numbers * Validate null number
- Loading branch information
1 parent
7949ac3
commit 13e6ede
Showing
4 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
export const DefaultLimit = 100; | ||
export const DefaultOffset = 0; |
This file contains 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 |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import { ApiPropertyOptional } from "@nestjs/swagger"; | ||
|
||
import { DefaultLimit, DefaultOffset } from "@config/constants/pagination-constants"; | ||
import { ListAllEntitiesDto } from "@dto/list-all-entities.dto"; | ||
import { StringToNumber } from "@helpers/string-to-number-validator"; | ||
import { IsSwaggerOptional } from "@helpers/optional-validator"; | ||
import { | ||
NullableStringToNumber, | ||
StringToNumber, | ||
} from "@helpers/string-to-number-validator"; | ||
import { ApiProperty, OmitType } from "@nestjs/swagger"; | ||
import { Transform } from "class-transformer"; | ||
import { IsOptional, IsNumber } from "class-validator"; | ||
|
||
export class ListAllApplicationsDto extends ListAllEntitiesDto { | ||
export class ListAllApplicationsDto extends OmitType(ListAllEntitiesDto, [ | ||
"limit", | ||
"offset", | ||
]) { | ||
@IsSwaggerOptional({ description: "Filter to one organization" }) | ||
@StringToNumber() | ||
organizationId?: number; | ||
|
||
@IsSwaggerOptional({ description: "Filter to one permission" }) | ||
@StringToNumber() | ||
permissionId?: number; | ||
|
||
@ApiProperty({ type: Number, required: false }) | ||
@IsOptional() | ||
@IsNumber() | ||
@Transform(({ value }) => NullableStringToNumber(value)) | ||
limit? = DefaultLimit; | ||
|
||
@ApiProperty({ type: Number, required: false }) | ||
@IsOptional() | ||
@IsNumber() | ||
@Transform(({ value }) => NullableStringToNumber(value)) | ||
offset? = DefaultOffset; | ||
} |
This file contains 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 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