Skip to content

Commit

Permalink
Поправит валидацию метода updateOffer
Browse files Browse the repository at this point in the history
  • Loading branch information
AdonaiJehosua committed Nov 4, 2024
1 parent b915d28 commit cdbd2c9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/shared/modules/offer/dto/update-offer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IsBoolean,
IsEnum,
IsInt, IsMongoId,
IsNumber,
IsNumber, IsOptional,
IsString,
Max,
MaxLength,
Expand All @@ -21,65 +21,80 @@ import {CityValidate, LocationValidate} from './city-and-location.dto.js';
import {CityAndLocationValidationMessages} from './city-and-location.messages.js';

export class UpdateOfferDto {
@IsOptional()
@IsString({message: UpdateOfferValidationMessages.title.minLength})
@MinLength(10, {message: UpdateOfferValidationMessages.title.minLength})
@MaxLength(100, {message: UpdateOfferValidationMessages.title.maxLength})
public title?: string;

@IsOptional()
@IsEnum(OfferType, {message: UpdateOfferValidationMessages.type.invalid})
public type?: OfferType;

@IsOptional()
@IsInt({message: UpdateOfferValidationMessages.price.invalidFormat})
@Min(100, {message: UpdateOfferValidationMessages.price.minValue})
@Max(100000, {message: UpdateOfferValidationMessages.price.maxValue})
public price?: number;

@IsOptional()
@Type(() => CityValidate)
@ValidateNested({message: CityAndLocationValidationMessages.city.invalid})
public city?: City;

@IsOptional()
@Type(() => LocationValidate)
@ValidateNested({message: CityAndLocationValidationMessages.location.invalid})
public location?: Location;

@IsOptional()
@IsBoolean({message: UpdateOfferValidationMessages.isFavorite.invalidFormat})
public isFavorite?: boolean;

@IsOptional()
@IsBoolean({message: UpdateOfferValidationMessages.isPremium.invalidFormat})
public isPremium?: boolean;

@IsOptional()
@IsNumber({maxDecimalPlaces: 1}, {message: UpdateOfferValidationMessages.rating.invalidFormat})
@Min(1, {message: UpdateOfferValidationMessages.price.minValue})
@Max(5, {message: UpdateOfferValidationMessages.price.maxValue})
public rating?: number;

@IsOptional()
@IsString({message: UpdateOfferValidationMessages.description.invalidFormat})
@MinLength(20, {message: UpdateOfferValidationMessages.description.minLength})
@MaxLength(1024, {message: UpdateOfferValidationMessages.description.maxLength})
public description?: string;

@IsOptional()
@IsArray({message: UpdateOfferValidationMessages.images.invalid})
@ArrayMinSize(6, {message: UpdateOfferValidationMessages.images.length})
@ArrayMaxSize(6, {message: UpdateOfferValidationMessages.images.length})
@IsString({each: true, message: UpdateOfferValidationMessages.images.invalidItem})
public images?: string[];

@IsOptional()
@IsString({message: UpdateOfferValidationMessages.image.invalidFormat})
public previewImage?: string;

@IsOptional()
@IsArray({message: UpdateOfferValidationMessages.offerGood.invalid})
@IsEnum(OfferGood, {each: true, message: UpdateOfferValidationMessages.offerGood.invalidType})
@ArrayUnique({message: UpdateOfferValidationMessages.offerGood.unique})
public goods?: OfferGood[];

@IsOptional()
@IsMongoId({message: UpdateOfferValidationMessages.hostId.invalidId})
public hostId?: string;

@IsOptional()
@IsInt({message: UpdateOfferValidationMessages.bedrooms.invalidFormat})
@Min(1, {message: UpdateOfferValidationMessages.bedrooms.minValue})
@Max(8, {message: UpdateOfferValidationMessages.bedrooms.maxValue})
public bedrooms?: number;

@IsOptional()
@IsInt({message: UpdateOfferValidationMessages.maxAdults.invalidFormat})
@Min(1, {message: UpdateOfferValidationMessages.maxAdults.minValue})
@Max(10, {message: UpdateOfferValidationMessages.maxAdults.maxValue})
Expand Down

0 comments on commit cdbd2c9

Please sign in to comment.