WIP AD DTO
This commit is contained in:
		
							parent
							
								
									b83baef1ee
								
							
						
					
					
						commit
						362452fc10
					
				| 
						 | 
					@ -26,7 +26,7 @@ message Ad {
 | 
				
			||||||
  MarginDurations marginDurations = 9;
 | 
					  MarginDurations marginDurations = 9;
 | 
				
			||||||
  optional int32 seatsPassenger = 10;
 | 
					  optional int32 seatsPassenger = 10;
 | 
				
			||||||
  optional int32 seatsDriver = 11;
 | 
					  optional int32 seatsDriver = 11;
 | 
				
			||||||
  bool strict = 12;
 | 
					  optional bool strict = 12;
 | 
				
			||||||
  repeated Address addresses = 13;
 | 
					  repeated Address addresses = 13;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,14 +51,15 @@ message MarginDurations {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
message Address {
 | 
					message Address {
 | 
				
			||||||
  float lon = 1;
 | 
					  int32 position =1;
 | 
				
			||||||
  float lat = 2;
 | 
					  float lon = 2;
 | 
				
			||||||
  string houseNumber = 3;
 | 
					  float lat = 3;
 | 
				
			||||||
  string street = 4;
 | 
					  string houseNumber = 4;
 | 
				
			||||||
  string locality = 5;
 | 
					  string street = 5;
 | 
				
			||||||
  string postalCode = 6;
 | 
					  string locality = 6;
 | 
				
			||||||
  string country = 7;
 | 
					  string postalCode = 7;
 | 
				
			||||||
  AddressType type = 8;
 | 
					  string country = 8;
 | 
				
			||||||
 | 
					  AddressType type = 9;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum AddressType {
 | 
					enum AddressType {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,10 +8,12 @@ import {
 | 
				
			||||||
  ValidateIf,
 | 
					  ValidateIf,
 | 
				
			||||||
  IsArray,
 | 
					  IsArray,
 | 
				
			||||||
  IsEnum,
 | 
					  IsEnum,
 | 
				
			||||||
 | 
					  IsNumber,
 | 
				
			||||||
 | 
					  ValidateNested,
 | 
				
			||||||
} from 'class-validator';
 | 
					} from 'class-validator';
 | 
				
			||||||
import { Frequency } from '../entities/frequency.enum';
 | 
					import { Frequency } from '../entities/frequency.enum';
 | 
				
			||||||
import { Address } from '../entities/address';
 | 
					 | 
				
			||||||
import { Transform, Type } from 'class-transformer';
 | 
					import { Transform, Type } from 'class-transformer';
 | 
				
			||||||
 | 
					import { AddressType } from '../entities/address.enum';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class CreateAdRequest {
 | 
					export class CreateAdRequest {
 | 
				
			||||||
  @IsString()
 | 
					  @IsString()
 | 
				
			||||||
| 
						 | 
					@ -35,10 +37,7 @@ export class CreateAdRequest {
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  passenger?: boolean;
 | 
					  passenger?: boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Transform(
 | 
					  @Transform(({ value }) => Frequency[value], { toClassOnly: true })
 | 
				
			||||||
    ({ value }) => (value == 1 ? Frequency.PUNCTUAL : Frequency.RECURRENT),
 | 
					 | 
				
			||||||
    { toClassOnly: true },
 | 
					 | 
				
			||||||
  )
 | 
					 | 
				
			||||||
  @IsEnum(Frequency)
 | 
					  @IsEnum(Frequency)
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  frequency: Frequency;
 | 
					  frequency: Frequency;
 | 
				
			||||||
| 
						 | 
					@ -130,22 +129,87 @@ export class CreateAdRequest {
 | 
				
			||||||
  seatsDriver?: number;
 | 
					  seatsDriver?: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @ValidateIf((ad) => (ad.driver ? false : true))
 | 
					  @ValidateIf((ad) => (ad.driver ? false : true))
 | 
				
			||||||
 | 
					  //@Transform(({ value }) => (value ? value : 0), { toClassOnly: true })
 | 
				
			||||||
  @IsOptional()
 | 
					  @IsOptional()
 | 
				
			||||||
  @IsInt()
 | 
					  @IsInt()
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  seatsPassenger?: number;
 | 
					  seatsPassenger?: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @IsOptional()
 | 
				
			||||||
 | 
					  @IsBoolean()
 | 
				
			||||||
 | 
					  @AutoMap()
 | 
				
			||||||
 | 
					  strict?: boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Type(() => Date)
 | 
					  @Type(() => Date)
 | 
				
			||||||
  @IsDate()
 | 
					  @IsDate()
 | 
				
			||||||
  @IsOptional()
 | 
					  @IsOptional()
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  createdAt?: Date;
 | 
					  createdAt?: Date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Type(() => Date)
 | 
					  @Type(() => Date)
 | 
				
			||||||
  @IsDate()
 | 
					  @IsDate()
 | 
				
			||||||
  @IsOptional()
 | 
					  @IsOptional()
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  updatedAt?: Date;
 | 
					  updatedAt?: Date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @IsArray()
 | 
					  @ValidateNested({ each: true })
 | 
				
			||||||
  @AutoMap(() => [Address])
 | 
					  @Transform(
 | 
				
			||||||
  addresses?: Array<Address>;
 | 
					    ({ value }) => {
 | 
				
			||||||
 | 
					      console.log('in dto');
 | 
				
			||||||
 | 
					      console.log(value);
 | 
				
			||||||
 | 
					      return value;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    { toClassOnly: true },
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  @Type(() => AddressDTO)
 | 
				
			||||||
 | 
					  @AutoMap(() => [AddressDTO])
 | 
				
			||||||
 | 
					  addresses: AddressDTO[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class AddressDTO {
 | 
				
			||||||
 | 
					  @IsNumber()
 | 
				
			||||||
 | 
					  @AutoMap()
 | 
				
			||||||
 | 
					  position: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @IsNumber()
 | 
				
			||||||
 | 
					  @AutoMap()
 | 
				
			||||||
 | 
					  lon: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @IsNumber()
 | 
				
			||||||
 | 
					  @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()
 | 
				
			||||||
 | 
					  @IsOptional()
 | 
				
			||||||
 | 
					  @AutoMap()
 | 
				
			||||||
 | 
					  country: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Transform(({ value }) => AddressType[value], { toClassOnly: true })
 | 
				
			||||||
 | 
					  @AutoMap()
 | 
				
			||||||
 | 
					  type: AddressType;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
export enum AddressType {
 | 
					export enum AddressType {
 | 
				
			||||||
  HOUSE_NUMBER = 'HOUSE_NUMBER',
 | 
					  HOUSE_NUMBER = 1,
 | 
				
			||||||
  STREET_ADDRESS = 'STREET_ADDRESS',
 | 
					  STREET_ADDRESS,
 | 
				
			||||||
  LOCALITY = 'LOCALITY',
 | 
					  LOCALITY,
 | 
				
			||||||
  VENUE = 'VENUE',
 | 
					  VENUE,
 | 
				
			||||||
  OTHER = 'OTHER',
 | 
					  OTHER,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,9 @@ export class Address {
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  lat: number;
 | 
					  lat: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @AutoMap()
 | 
				
			||||||
 | 
					  name?: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @AutoMap()
 | 
					  @AutoMap()
 | 
				
			||||||
  houseNumber?: string;
 | 
					  houseNumber?: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
export enum Frequency {
 | 
					export enum Frequency {
 | 
				
			||||||
  PUNCTUAL = 'PUNCTUAL',
 | 
					  PUNCTUAL = 1,
 | 
				
			||||||
  RECURRENT = 'RECURRENT',
 | 
					  RECURRENT,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue