added more security check rules in dtos

This commit is contained in:
Kevsl 2024-06-11 09:52:47 +02:00
parent 1171e5e13c
commit 0ba8b52be3
7 changed files with 82 additions and 7 deletions

View File

@ -1,11 +1,20 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import {
IsEmail,
IsNotEmpty,
IsOptional,
IsString,
MaxLength,
MinLength,
} from 'class-validator';
export class AuthRegisterDto { export class AuthRegisterDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'FirstName', description: 'FirstName',
example: 'Thomas', example: 'Thomas',
}) })
@MinLength(1)
@MaxLength(50)
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
firstName: string; firstName: string;
@ -15,6 +24,8 @@ export class AuthRegisterDto {
description: 'Last Name', description: 'Last Name',
example: 'Anderson', example: 'Anderson',
}) })
@MinLength(1)
@MaxLength(50)
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
lastName: string; lastName: string;
@ -24,6 +35,8 @@ export class AuthRegisterDto {
description: 'Pseudo', description: 'Pseudo',
example: 'Néo', example: 'Néo',
}) })
@MinLength(1)
@MaxLength(50)
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
pseudo: string; pseudo: string;
@ -33,6 +46,8 @@ export class AuthRegisterDto {
description: 'User city', description: 'User city',
example: 'Aix les bains', example: 'Aix les bains',
}) })
@MinLength(1)
@MaxLength(70)
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
city: string; city: string;
@ -42,6 +57,7 @@ export class AuthRegisterDto {
description: 'email', description: 'email',
example: 'neo@matrix.fr', example: 'neo@matrix.fr',
}) })
@MaxLength(255)
@IsEmail() @IsEmail()
@IsNotEmpty() @IsNotEmpty()
email: string; email: string;

View File

@ -1,12 +1,23 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsString } from 'class-validator'; import {
IsNumber,
IsString,
IsUUID,
Max,
MaxLength,
Min,
MinLength,
} from 'class-validator';
export class BuyCryptoDto { export class BuyCryptoDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'Cryptocurrency UUID', description: 'Cryptocurrency UUID',
example: '12121-DSZD-E221212-2121221', example: '12121-DSZD-E221212-2121221',
}) })
@MinLength(1)
@MaxLength(50)
@IsString() @IsString()
@IsUUID()
id_crypto: string; id_crypto: string;
@ApiProperty({ @ApiProperty({
@ -14,6 +25,8 @@ export class BuyCryptoDto {
description: 'Amount of token traded', description: 'Amount of token traded',
example: 2, example: 2,
}) })
@Min(1)
@Max(1000)
@IsNumber() @IsNumber()
amount: number; amount: number;
} }

View File

@ -1,11 +1,22 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsString, IsUrl } from 'class-validator'; import {
IsNumber,
IsPositive,
IsString,
IsUrl,
Max,
MaxLength,
Min,
MinLength,
} from 'class-validator';
export class CryptoDto { export class CryptoDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'Cryptocurrency name', description: 'Cryptocurrency name',
example: 'BTC', example: 'BTC',
}) })
@MaxLength(50)
@MinLength(1)
@IsString() @IsString()
name: string; name: string;
@ -14,6 +25,9 @@ export class CryptoDto {
description: 'Value for the cryptocurrency in $', description: 'Value for the cryptocurrency in $',
example: 1, example: 1,
}) })
@Min(1)
@Max(10000)
@IsPositive()
@IsNumber() @IsNumber()
value: number; value: number;
@ -22,6 +36,9 @@ export class CryptoDto {
description: 'Quantity of tokens available on the platform', description: 'Quantity of tokens available on the platform',
example: 100, example: 100,
}) })
@Min(1)
@Max(10000)
@IsPositive()
@IsNumber() @IsNumber()
quantity: number; quantity: number;
@ -30,6 +47,7 @@ export class CryptoDto {
description: 'Image for the cryptocurrency in ', description: 'Image for the cryptocurrency in ',
example: 'https://myImage/com', example: 'https://myImage/com',
}) })
@MaxLength(255)
@IsUrl() @IsUrl()
@IsString() @IsString()
image: string; image: string;

View File

@ -1,12 +1,22 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsPositive, IsString } from 'class-validator'; import {
IsNumber,
IsPositive,
IsString,
IsUUID,
Max,
MaxLength,
Min,
} from 'class-validator';
export class OfferDto { export class OfferDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'Cryptocurrency UUID', description: 'Cryptocurrency UUID',
example: '12121-DSZD-E221212-2121221', example: '12121-DSZD-E221212-2121221',
}) })
@MaxLength(50)
@IsString() @IsString()
@IsUUID()
id_crypto: string; id_crypto: string;
@ApiProperty({ @ApiProperty({
@ -15,6 +25,8 @@ export class OfferDto {
description: 'Amount traded ', description: 'Amount traded ',
example: 21, example: 21,
}) })
@Min(1)
@Max(1000)
@IsNumber() @IsNumber()
@IsPositive() @IsPositive()
amount: number; amount: number;

View File

@ -1,11 +1,21 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsString } from 'class-validator'; import {
IsNumber,
IsPositive,
IsString,
Max,
MaxLength,
Min,
MinLength,
} from 'class-validator';
export class PromoCodeDto { export class PromoCodeDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'Name of the PromoCOde', description: 'Name of the PromoCOde',
example: 'FILOU10', example: 'FILOU10',
}) })
@MinLength(1)
@MaxLength(50)
@IsString() @IsString()
name: string; name: string;
@ -14,6 +24,9 @@ export class PromoCodeDto {
description: 'Dollars given for account creation when promoCode applied', description: 'Dollars given for account creation when promoCode applied',
example: 100, example: 100,
}) })
@IsPositive()
@Min(1)
@Max(3000)
@IsNumber() @IsNumber()
value: number; value: number;
} }

View File

@ -1,11 +1,13 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator'; import { IsString, MaxLength, MinLength } from 'class-validator';
export class RoleDto { export class RoleDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'Role Name', description: 'Role Name',
example: 'user', example: 'user',
}) })
@MinLength(1)
@MaxLength(50)
@IsString() @IsString()
name: string; name: string;
} }

View File

@ -1,11 +1,12 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator'; import { IsNotEmpty, IsString, IsUUID } from 'class-validator';
export class TradeDto { export class TradeDto {
@ApiProperty({ @ApiProperty({
type: String, type: String,
description: 'Offer UUID ', description: 'Offer UUID ',
example: '121212-DSDZ1-21212DJDZ-31313', example: '121212-DSDZ1-21212DJDZ-31313',
}) })
@IsUUID()
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
id_offer: string; id_offer: string;