WIP ad creation address mapping troubleshooting

This commit is contained in:
Grégoire Chevalier 2023-05-16 14:43:52 +02:00
parent 5ed2c562d5
commit 8544b2f54e
8 changed files with 36 additions and 17 deletions

View File

@ -42,7 +42,7 @@ export class AdController {
@GrpcMethod('AdsService', 'Create')
async createAd(data: CreateAdRequest): Promise<AdPresenter> {
try {
console.log('controler');
console.log('controler--------------------------------');
console.log(data);
console.log('-----------------------------------------');
const ad = await this._commandBus.execute(new CreateAdCommand(data));

View File

@ -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])

View File

@ -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;

View File

@ -125,9 +125,8 @@ export class Ad {
@AutoMap()
updatedAt?: Date;
@Type(() => Address)
@ArrayMinSize(2)
@ValidateNested({ each: true })
@AutoMap()
@AutoMap(() => [Address])
addresses: Address[];
}

View File

@ -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;

View File

@ -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));

View File

@ -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),
),
);
};
}

View File

@ -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,