From c301d1ceba4204617423724df691da40d8bada40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Chevalier?= Date: Tue, 16 May 2023 16:57:58 +0200 Subject: [PATCH] WIP adresses inserting troubleshooting --- src/modules/ad/adapters/primaries/ad.controller.ts | 1 + src/modules/ad/domain/dtos/create-ad.request.ts | 2 +- src/modules/ad/domain/usecases/create-ad.usecase.ts | 8 ++++++++ src/modules/ad/mappers/ad.profile.ts | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/ad/adapters/primaries/ad.controller.ts b/src/modules/ad/adapters/primaries/ad.controller.ts index 3558ae9..27010e4 100644 --- a/src/modules/ad/adapters/primaries/ad.controller.ts +++ b/src/modules/ad/adapters/primaries/ad.controller.ts @@ -11,6 +11,7 @@ import { Ad } from '../../domain/entities/ad'; import { CreateAdRequest } from '../../domain/dtos/create-ad.request'; import { CreateAdCommand } from '../../commands/create-ad.command'; import { DatabaseException } from '../../../database/exceptions/database.exception'; +import { AddressDTO } from '../../domain/dtos/create.address.dto'; @UsePipes( new RpcValidationPipe({ diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index 8284cac..6014f21 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -101,6 +101,6 @@ export class CreateAdRequest { @Type(() => AddressDTO) @HasProperPositionIndexes() @ValidateNested({ each: true }) - @AutoMap(() => [AddressDTO]) + @AutoMap() addresses: AddressDTO[]; } diff --git a/src/modules/ad/domain/usecases/create-ad.usecase.ts b/src/modules/ad/domain/usecases/create-ad.usecase.ts index 02a0aff..e3316b9 100644 --- a/src/modules/ad/domain/usecases/create-ad.usecase.ts +++ b/src/modules/ad/domain/usecases/create-ad.usecase.ts @@ -9,6 +9,7 @@ import { CreateAdRequest } from '../dtos/create-ad.request'; import { Ad } from '../entities/ad'; import { IProvideParams } from '../interfaces/param-provider.interface'; import { DefaultParams } from '../types/default-params.type'; +import { Address } from '../entities/address'; @CommandHandler(CreateAdCommand) export class CreateAdUseCase { @@ -25,6 +26,7 @@ export class CreateAdUseCase { } async execute(command: CreateAdCommand): Promise { + console.log('before mapping '); const entity: Ad = this._mapper.map( command.createAdRequest, CreateAdRequest, @@ -54,6 +56,12 @@ export class CreateAdUseCase { typeof entity.strict === 'boolean' ? entity.strict : (entity.strict = this.defaultParams.STRICT); + + if (typeof entity.addresses[0].position === 'undefined') { + for (let i = 0; i < entity.addresses.length; i++) { + entity.addresses[i].position = i; + } + } try { console.log('before ***********************************'); console.log(entity); diff --git a/src/modules/ad/mappers/ad.profile.ts b/src/modules/ad/mappers/ad.profile.ts index ba0bfa3..3b2e4a6 100644 --- a/src/modules/ad/mappers/ad.profile.ts +++ b/src/modules/ad/mappers/ad.profile.ts @@ -15,6 +15,7 @@ export class AdProfile extends AutomapperProfile { override get profile() { return (mapper) => { + createMap(mapper, Address, AddressDTO); createMap(mapper, Ad, AdPresenter); createMap( mapper, @@ -76,6 +77,10 @@ export class AdProfile extends AutomapperProfile { (destination) => destination.sunTime, mapFrom((source) => source.schedule.sun), ), + forMember( + (destination) => destination.addresses, + mapFrom((source) => source.addresses), + ), ); }; }