-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Поправит валидационные сообщения метода createOffer, осуществит валид…
…ацию для комментариев и пользователей
- Loading branch information
AdonaiJehosua
committed
Nov 4, 2024
1 parent
cdbd2c9
commit 73fed94
Showing
11 changed files
with
118 additions
and
14 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
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,6 +1,21 @@ | ||
import {IsMongoId, IsNumber, IsString, Max, MaxLength, Min, MinLength} from 'class-validator'; | ||
|
||
import {CreateCommentValidationMessages} from './create-comment.messages.js'; | ||
|
||
export class CreateCommentDto { | ||
@IsString({message: CreateCommentValidationMessages.text.invalidFormat}) | ||
@MinLength(10, {message: CreateCommentValidationMessages.text.minLength}) | ||
@MaxLength(100, {message: CreateCommentValidationMessages.text.maxLength}) | ||
public text: string; | ||
|
||
@IsNumber({maxDecimalPlaces: 1}, {message: CreateCommentValidationMessages.rating.invalidFormat}) | ||
@Min(1, {message: CreateCommentValidationMessages.rating.minValue}) | ||
@Max(5, {message: CreateCommentValidationMessages.rating.maxValue}) | ||
public rating: number; | ||
|
||
@IsMongoId({message: CreateCommentValidationMessages.offerId.invalidId}) | ||
public authorId: string; | ||
|
||
@IsMongoId({message: CreateCommentValidationMessages.offerId.invalidId}) | ||
public offerId: string; | ||
} |
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,18 @@ | ||
export const CreateCommentValidationMessages = { | ||
text: { | ||
invalidFormat: 'text must be a string', | ||
minLength: 'minimum text length must be 5 characters', | ||
maxLength: 'maximum text length must be 1024 characters', | ||
}, | ||
rating: { | ||
invalidFormat: 'rating must be a number with maximum 1 decimal place', | ||
minValue: 'minimum rating is 1', | ||
maxValue: 'maximum rating is 5', | ||
}, | ||
authorId: { | ||
invalidId: 'author id field must be a valid id', | ||
}, | ||
offerId: { | ||
invalidId: 'offer id field must be a valid id', | ||
} | ||
} as const; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
import {IsBoolean, IsEmail, IsString, MaxLength, MinLength} from 'class-validator'; | ||
|
||
import {CreateUserValidationMessages} from './create-user.messages.js'; | ||
|
||
export class CreateUserDto { | ||
@IsString({message: CreateUserValidationMessages.name.invalidFormat}) | ||
@MinLength(10, {message: CreateUserValidationMessages.name.minLength}) | ||
@MaxLength(100, {message: CreateUserValidationMessages.name.maxLength}) | ||
public name: string; | ||
|
||
@IsString({message: CreateUserValidationMessages.avatarUrl.invalidFormat}) | ||
public avatarUrl: string; | ||
|
||
@IsBoolean({message: CreateUserValidationMessages.isPro.invalidFormat}) | ||
public isPro: boolean; | ||
|
||
@IsEmail({}, {message: CreateUserValidationMessages.email.invalidFormat}) | ||
public email: string; | ||
public token: string; | ||
|
||
@IsString({message: CreateUserValidationMessages.email.invalidFormat}) | ||
public password: string; | ||
} |
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,19 @@ | ||
export const CreateUserValidationMessages = { | ||
name: { | ||
invalidFormat: 'name must be a string', | ||
minLength: 'minimum name length must be 1', | ||
maxLength: 'maximum name length must be 15', | ||
}, | ||
avatarUrl: { | ||
invalidFormat: 'avatar url must be a string', | ||
}, | ||
isPro: { | ||
invalidFormat: 'isPro flag must be a boolean', | ||
}, | ||
email: { | ||
invalidFormat: 'email email must be in the correct format', | ||
}, | ||
password: { | ||
invalidFormat: 'password must be a string', | ||
} | ||
} as const; |
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,4 +1,11 @@ | ||
import {IsEmail, IsString} from 'class-validator'; | ||
|
||
import {LoginUserValidationMessages} from './login-user.messages.js'; | ||
|
||
export class LoginUserDto { | ||
@IsEmail({}, {message: LoginUserValidationMessages.email.invalidFormat}) | ||
public email: string; | ||
|
||
@IsString({message: LoginUserValidationMessages.password.invalidFormat}) | ||
public password: string; | ||
} |
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,8 @@ | ||
export const LoginUserValidationMessages = { | ||
email: { | ||
invalidFormat: 'email email must be in the correct format' | ||
}, | ||
password: { | ||
invalidFormat: 'password must be a string' | ||
} | ||
} as const; |
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