import { IsNotEmpty, IsOptional, IsPostalCode, IsString } from 'class-validator'; import { Address } from '../entities/Address'; export class CreateAddress { /** * The address's description. */ @IsString() @IsOptional() description?: string; /** * The address's first line. * Containing the street and house number. */ @IsString() @IsNotEmpty() address1: string; /** * The address's second line. * Containing optional information. */ @IsString() @IsOptional() address2?: string; /** * The address's postal code. */ @IsString() @IsNotEmpty() @IsPostalCode("DE") postalcode: string; /** * The address's city. */ @IsString() @IsNotEmpty() city: string; /** * The address's country. */ @IsString() @IsNotEmpty() country: string; /** * Creates a Address object based on this. */ public toAddress(): Address { let newAddress: Address = new Address(); newAddress.address1 = this.address1; newAddress.address2 = this.address2; newAddress.postalcode = this.postalcode; newAddress.city = this.city; newAddress.country = this.country; return newAddress; } }