margin dto working properly

This commit is contained in:
Grégoire Chevalier 2023-05-12 11:12:58 +02:00
parent b035655bc6
commit 7036a8be55
6 changed files with 141 additions and 85 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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