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