diff --git a/src/modules/ad/adapters/primaries/ad.proto b/src/modules/ad/adapters/primaries/ad.proto index 63a07d1..7014838 100644 --- a/src/modules/ad/adapters/primaries/ad.proto +++ b/src/modules/ad/adapters/primaries/ad.proto @@ -5,7 +5,7 @@ package ad; service AdsService { rpc FindOneByUuid(AdByUuid) returns (Ad); rpc FindAll(AdFilter) returns (Ads); - rpc Create(Ad) returns (Ad); + rpc Create(Ad) returns (AdByUuid); rpc Update(Ad) returns (Ad); rpc Delete(AdByUuid) returns (Empty); } diff --git a/src/modules/ad/commands/create-ad.command.ts b/src/modules/ad/commands/create-ad.command.ts index b1a8eba..0267ccd 100644 --- a/src/modules/ad/commands/create-ad.command.ts +++ b/src/modules/ad/commands/create-ad.command.ts @@ -6,12 +6,5 @@ export class CreateAdCommand { constructor(request: CreateAdRequest) { this.createAdRequest = request; console.log('req creation'); - console.log(this.createAdRequest.monMargin); - console.log(this.createAdRequest.tueMargin); - console.log(this.createAdRequest.wedMargin); - console.log(this.createAdRequest.thuMargin); - console.log(this.createAdRequest.friMargin); - console.log(this.createAdRequest.satMargin); - console.log(this.createAdRequest.sunMargin); } } diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index 5f52944..34a0067 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -16,6 +16,8 @@ import { import { Frequency } from '../entities/frequency.enum'; import { Transform, Type } from 'class-transformer'; import { mappingKeyToFrequency } from './utils/frequency.mapping'; +import { MarginDTO } from './create.margin.dto'; +import { ScheduleDTO } from './create.schedule.dto'; // TODO mapping schedule and margin (proto object to margin and schedule fields ) export class CreateAdRequest { @@ -58,84 +60,15 @@ export class CreateAdRequest { @AutoMap() toDate?: Date; - @IsDate() - @IsOptional() - @AutoMap() - monTime?: string; + @ValidateNested({ each: true }) + @Type(() => ScheduleDTO) + @AutoMap(() => ScheduleDTO) + schedule: ScheduleDTO; - @IsString() - @IsOptional() - @AutoMap() - tueTime?: string; - - @IsString() - @IsOptional() - @AutoMap() - wedTime?: string; - - @IsString() - @IsOptional() - @AutoMap() - thuTime?: string; - - @IsString() - @IsOptional() - @AutoMap() - friTime?: string; - - @IsString() - @IsOptional() - @AutoMap() - satTime?: string; - - @IsString() - @IsOptional() - @AutoMap() - sunTime?: string; - - @Transform( - ({ value }) => { - console.log(value); - return value; - }, - { - toClassOnly: true, - }, - ) - @IsInt() - @IsOptional() - @AutoMap() - monMargin?: number; - - @IsInt() - @IsOptional() - @AutoMap() - tueMargin?: number; - - @IsInt() - @IsOptional() - @AutoMap() - wedMargin?: number; - - @IsInt() - @IsOptional() - @AutoMap() - thuMargin?: number; - - @IsInt() - @IsOptional() - @AutoMap() - friMargin?: number; - - @IsInt() - @IsOptional() - @AutoMap() - satMargin?: number; - - @IsInt() - @IsOptional() - @AutoMap() - sunMargin?: number; + @ValidateNested({ each: true }) + @Type(() => MarginDTO) + @AutoMap(() => MarginDTO) + marginDurations: MarginDTO; @ValidateIf((ad) => ad.driver) @IsInt() diff --git a/src/modules/ad/domain/dtos/create.address.dto.ts b/src/modules/ad/domain/dtos/create.address.dto.ts new file mode 100644 index 0000000..6c0f933 --- /dev/null +++ b/src/modules/ad/domain/dtos/create.address.dto.ts @@ -0,0 +1,51 @@ +import { AutoMap } from '@automapper/classes'; +import { + IsInt, + IsLatitude, + IsLongitude, + IsOptional, + IsString, +} from 'class-validator'; + +export class AddressDTO { + @IsInt() + @AutoMap() + position: number; + + @IsLongitude() + @AutoMap() + lon: number; + + @IsLatitude() + @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() + @AutoMap() + country: string; +} diff --git a/src/modules/ad/domain/dtos/create.margin.dto.ts b/src/modules/ad/domain/dtos/create.margin.dto.ts new file mode 100644 index 0000000..698afaa --- /dev/null +++ b/src/modules/ad/domain/dtos/create.margin.dto.ts @@ -0,0 +1,40 @@ +import { AutoMap } from '@automapper/classes'; +import { Transform } from 'class-transformer'; +import { IsInt, IsOptional } from 'class-validator'; + +export class MarginDTO { + @IsInt() + @IsOptional() + @AutoMap() + mon?: number; + + @IsInt() + @IsOptional() + @AutoMap() + tue?: number; + + @IsInt() + @IsOptional() + @AutoMap() + wed?: number; + + @IsInt() + @IsOptional() + @AutoMap() + thu?: number; + + @IsInt() + @IsOptional() + @AutoMap() + fri?: number; + + @IsInt() + @IsOptional() + @AutoMap() + sat?: number; + + @IsInt() + @IsOptional() + @AutoMap() + sun?: number; +} diff --git a/src/modules/ad/domain/dtos/create.schedule.dto.ts b/src/modules/ad/domain/dtos/create.schedule.dto.ts new file mode 100644 index 0000000..7ef0ad2 --- /dev/null +++ b/src/modules/ad/domain/dtos/create.schedule.dto.ts @@ -0,0 +1,39 @@ +import { AutoMap } from '@automapper/classes'; +import { IsOptional, IsString } from 'class-validator'; + +export class ScheduleDTO { + @IsString() + @IsOptional() + @AutoMap() + monTime?: string; + + @IsString() + @IsOptional() + @AutoMap() + tueTime?: string; + + @IsString() + @IsOptional() + @AutoMap() + wedTime?: string; + + @IsString() + @IsOptional() + @AutoMap() + thuTime?: string; + + @IsString() + @IsOptional() + @AutoMap() + friTime?: string; + + @IsString() + @IsOptional() + @AutoMap() + satTime?: string; + + @IsString() + @IsOptional() + @AutoMap() + sunTime?: string; +}