From 2bd0cbadbed6b04136d7fc3c6f0f5e8ef35d982d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:03:41 +0100 Subject: [PATCH] Added the address class ref #11 --- src/models/Address.ts | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/models/Address.ts diff --git a/src/models/Address.ts b/src/models/Address.ts new file mode 100644 index 0000000..df8e2ca --- /dev/null +++ b/src/models/Address.ts @@ -0,0 +1,73 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsPostalCode, + IsString, +} from "class-validator"; + +/** + * Defines a address (to be used for contact information). +*/ +@Entity() +export class Address { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The address's description. + */ + @Column() + @IsString() + @IsOptional() + description?: string; + + /** + * The address's first line. + * Containing the street and house number. + */ + @Column() + @IsString() + @IsNotEmpty() + address1: string; + + /** + * The address's second line. + * Containing optional information. + */ + @Column() + @IsString() + @IsOptional() + address2?: string; + + /** + * The address's postal code. + */ + @Column() + @IsString() + @IsNotEmpty() + @IsPostalCode("DE") + postalcode: string; + + /** + * The address's city. + */ + @Column() + @IsString() + @IsNotEmpty() + city: string; + + /** + * The address's country. + */ + @Column() + @IsString() + @IsNotEmpty() + country: string; +}