diff --git a/src/modules/ad/adapters/primaries/ad.proto b/src/modules/ad/adapters/primaries/ad.proto index 8bcf611..3b37b64 100644 --- a/src/modules/ad/adapters/primaries/ad.proto +++ b/src/modules/ad/adapters/primaries/ad.proto @@ -26,7 +26,7 @@ message Ad { MarginDurations marginDurations = 9; optional int32 seatsPassenger = 10; optional int32 seatsDriver = 11; - bool strict = 12; + optional bool strict = 12; repeated Address addresses = 13; } @@ -51,14 +51,15 @@ message MarginDurations { } message Address { - float lon = 1; - float lat = 2; - string houseNumber = 3; - string street = 4; - string locality = 5; - string postalCode = 6; - string country = 7; - AddressType type = 8; + int32 position =1; + float lon = 2; + float lat = 3; + string houseNumber = 4; + string street = 5; + string locality = 6; + string postalCode = 7; + string country = 8; + AddressType type = 9; } enum AddressType { diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index 17ab6f4..7181670 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -8,10 +8,12 @@ import { ValidateIf, IsArray, IsEnum, + IsNumber, + ValidateNested, } from 'class-validator'; import { Frequency } from '../entities/frequency.enum'; -import { Address } from '../entities/address'; import { Transform, Type } from 'class-transformer'; +import { AddressType } from '../entities/address.enum'; export class CreateAdRequest { @IsString() @@ -35,10 +37,7 @@ export class CreateAdRequest { @AutoMap() passenger?: boolean; - @Transform( - ({ value }) => (value == 1 ? Frequency.PUNCTUAL : Frequency.RECURRENT), - { toClassOnly: true }, - ) + @Transform(({ value }) => Frequency[value], { toClassOnly: true }) @IsEnum(Frequency) @AutoMap() frequency: Frequency; @@ -130,22 +129,87 @@ export class CreateAdRequest { seatsDriver?: number; @ValidateIf((ad) => (ad.driver ? false : true)) + //@Transform(({ value }) => (value ? value : 0), { toClassOnly: true }) @IsOptional() @IsInt() @AutoMap() seatsPassenger?: number; + + @IsOptional() + @IsBoolean() + @AutoMap() + strict?: boolean; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() createdAt?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() updatedAt?: Date; - @IsArray() - @AutoMap(() => [Address]) - addresses?: Array
; + @ValidateNested({ each: true }) + @Transform( + ({ value }) => { + console.log('in dto'); + console.log(value); + return value; + }, + { toClassOnly: true }, + ) + @Type(() => AddressDTO) + @AutoMap(() => [AddressDTO]) + addresses: AddressDTO[]; +} + +class AddressDTO { + @IsNumber() + @AutoMap() + position: number; + + @IsNumber() + @AutoMap() + lon: number; + + @IsNumber() + @AutoMap() + lat: number; + + @IsString() + @IsOptional() + @AutoMap() + name?: string; + + @IsString() + @IsOptional() + @AutoMap() + houseNumber?: string; + + @IsString() + @IsOptional() + @AutoMap() + street?: string; + + @IsString() + @IsOptional() + @AutoMap() + locality: string; + + @IsString() + @IsOptional() + @AutoMap() + postalCode: string; + + @IsString() + @IsOptional() + @AutoMap() + country: string; + + @Transform(({ value }) => AddressType[value], { toClassOnly: true }) + @AutoMap() + type: AddressType; } diff --git a/src/modules/ad/domain/entities/address.enum.ts b/src/modules/ad/domain/entities/address.enum.ts index 3aac4a4..934012f 100644 --- a/src/modules/ad/domain/entities/address.enum.ts +++ b/src/modules/ad/domain/entities/address.enum.ts @@ -1,7 +1,7 @@ export enum AddressType { - HOUSE_NUMBER = 'HOUSE_NUMBER', - STREET_ADDRESS = 'STREET_ADDRESS', - LOCALITY = 'LOCALITY', - VENUE = 'VENUE', - OTHER = 'OTHER', + HOUSE_NUMBER = 1, + STREET_ADDRESS, + LOCALITY, + VENUE, + OTHER, } diff --git a/src/modules/ad/domain/entities/address.ts b/src/modules/ad/domain/entities/address.ts index 22f6e0e..6b9a783 100644 --- a/src/modules/ad/domain/entities/address.ts +++ b/src/modules/ad/domain/entities/address.ts @@ -14,6 +14,9 @@ export class Address { @AutoMap() lat: number; + @AutoMap() + name?: string; + @AutoMap() houseNumber?: string; diff --git a/src/modules/ad/domain/entities/frequency.enum.ts b/src/modules/ad/domain/entities/frequency.enum.ts index 0126874..629b865 100644 --- a/src/modules/ad/domain/entities/frequency.enum.ts +++ b/src/modules/ad/domain/entities/frequency.enum.ts @@ -1,4 +1,4 @@ export enum Frequency { - PUNCTUAL = 'PUNCTUAL', - RECURRENT = 'RECURRENT', + PUNCTUAL = 1, + RECURRENT, }