diff --git a/src/modules/ad/adapters/primaries/ad.controller.ts b/src/modules/ad/adapters/primaries/ad.controller.ts index 0696ee8..3558ae9 100644 --- a/src/modules/ad/adapters/primaries/ad.controller.ts +++ b/src/modules/ad/adapters/primaries/ad.controller.ts @@ -42,7 +42,7 @@ export class AdController { @GrpcMethod('AdsService', 'Create') async createAd(data: CreateAdRequest): Promise { try { - console.log('controler'); + console.log('controler--------------------------------'); console.log(data); console.log('-----------------------------------------'); const ad = await this._commandBus.execute(new CreateAdCommand(data)); diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index dc29c37..672d698 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -10,6 +10,7 @@ import { ValidateIf, ArrayMinSize, IsNotEmptyObject, + IsUUID, } from 'class-validator'; import { Frequency } from '../types/frequency.enum'; import { Transform, Type } from 'class-transformer'; @@ -21,7 +22,12 @@ import { HasProperPassengerSeats } from './utils/has-passenger-seats.validator'; import { HasProperDriverSeats } from './utils/has-driver-seats.validator'; export class CreateAdRequest { - @IsString() + @IsOptional() + @IsUUID(4) + @AutoMap() + uuid?: string; + + @IsUUID(4) @AutoMap() userUuid: string; @@ -90,7 +96,6 @@ export class CreateAdRequest { @AutoMap() strict?: boolean; - @Type(() => AddressDTO) @ArrayMinSize(2) @ValidateNested({ each: true }) @AutoMap(() => [AddressDTO]) diff --git a/src/modules/ad/domain/dtos/create.address.dto.ts b/src/modules/ad/domain/dtos/create.address.dto.ts index 378af10..18872f7 100644 --- a/src/modules/ad/domain/dtos/create.address.dto.ts +++ b/src/modules/ad/domain/dtos/create.address.dto.ts @@ -5,9 +5,20 @@ import { IsLongitude, IsOptional, IsString, + IsUUID, } from 'class-validator'; export class AddressDTO { + @IsOptional() + @IsUUID(4) + @AutoMap() + uuid?: string; + + @IsOptional() + @IsUUID(4) + @AutoMap() + adUuid?: string; + @IsInt() @AutoMap() position: number; diff --git a/src/modules/ad/domain/entities/ad.ts b/src/modules/ad/domain/entities/ad.ts index 4fb1554..1d3f04e 100644 --- a/src/modules/ad/domain/entities/ad.ts +++ b/src/modules/ad/domain/entities/ad.ts @@ -125,9 +125,8 @@ export class Ad { @AutoMap() updatedAt?: Date; - @Type(() => Address) @ArrayMinSize(2) @ValidateNested({ each: true }) - @AutoMap() + @AutoMap(() => [Address]) addresses: Address[]; } diff --git a/src/modules/ad/domain/entities/address.ts b/src/modules/ad/domain/entities/address.ts index abda857..756688f 100644 --- a/src/modules/ad/domain/entities/address.ts +++ b/src/modules/ad/domain/entities/address.ts @@ -1,9 +1,16 @@ import { AutoMap } from '@automapper/classes'; +import { IsInt, IsUUID } from 'class-validator'; export class Address { + @IsUUID(4) @AutoMap() - uuid?: string; + uuid: string; + @IsUUID(4) + @AutoMap() + adUuid: string; + + @IsInt() @AutoMap() position: number; diff --git a/src/modules/ad/domain/usecases/create-ad.usecase.ts b/src/modules/ad/domain/usecases/create-ad.usecase.ts index cebe029..02a0aff 100644 --- a/src/modules/ad/domain/usecases/create-ad.usecase.ts +++ b/src/modules/ad/domain/usecases/create-ad.usecase.ts @@ -30,9 +30,6 @@ export class CreateAdUseCase { CreateAdRequest, Ad, ); - console.log('usecase'); - console.log(entity.addresses[0]); - console.log('-----------------------------------------'); typeof entity.monMargin === 'number' ? entity.monMargin : (entity.monMargin = this.defaultParams.MON_MARGIN); @@ -58,6 +55,9 @@ export class CreateAdUseCase { ? entity.strict : (entity.strict = this.defaultParams.STRICT); try { + console.log('before ***********************************'); + console.log(entity); + console.log('******************************************'); this.ad = await this._repository.create(entity); // this._messager.publish('ad.create', JSON.stringify(ad)); // this._messager.publish('logging.ad.create.info', JSON.stringify(ad)); diff --git a/src/modules/ad/mappers/ad.profile.ts b/src/modules/ad/mappers/ad.profile.ts index 0a98fc9..ba0bfa3 100644 --- a/src/modules/ad/mappers/ad.profile.ts +++ b/src/modules/ad/mappers/ad.profile.ts @@ -4,6 +4,8 @@ import { Injectable } from '@nestjs/common'; import { Ad } from '../domain/entities/ad'; import { AdPresenter } from '../adapters/primaries/ad.presenter'; import { CreateAdRequest } from '../domain/dtos/create-ad.request'; +import { Address } from '../domain/entities/address'; +import { AddressDTO } from '../domain/dtos/create.address.dto'; @Injectable() export class AdProfile extends AutomapperProfile { @@ -74,10 +76,6 @@ export class AdProfile extends AutomapperProfile { (destination) => destination.sunTime, mapFrom((source) => source.schedule.sun), ), - forMember( - (destination) => destination.addresses, - mapFrom((source) => source.addresses), - ), ); }; } diff --git a/src/modules/ad/tests/unit/create-ad.usecase.spec.ts b/src/modules/ad/tests/unit/create-ad.usecase.spec.ts index e2028e1..a483a0d 100644 --- a/src/modules/ad/tests/unit/create-ad.usecase.spec.ts +++ b/src/modules/ad/tests/unit/create-ad.usecase.spec.ts @@ -1,7 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; import { CreateAdUseCase } from '../../domain/usecases/create-ad.usecase'; import { CreateAdRequest } from '../../domain/dtos/create-ad.request'; -import { Address } from '../../domain/entities/address'; import { Messager } from '../../adapters/secondaries/messager'; import { AdsRepository } from '../../adapters/secondaries/ads.repository'; import { CreateAdCommand } from '../../commands/create-ad.command'; @@ -10,9 +9,9 @@ import { classes } from '@automapper/classes'; import { Frequency } from '../../domain/types/frequency.enum'; import { Ad } from '../../domain/entities/ad'; import { AdProfile } from '../../mappers/ad.profile'; -import { DefaultParams } from '../../domain/types/default-params.type'; +import { AddressDTO } from '../../domain/dtos/create.address.dto'; -const mockAddress1: Address = { +const mockAddress1: AddressDTO = { position: 0, lon: 48.68944505415954, lat: 6.176510296462267, @@ -22,7 +21,7 @@ const mockAddress1: Address = { postalCode: '54000', country: 'France', }; -const mockAddress2: Address = { +const mockAddress2: AddressDTO = { position: 1, lon: 48.8566, lat: 2.3522,