67 lines
1.2 KiB
TypeScript
67 lines
1.2 KiB
TypeScript
import {
|
|
IsNotEmpty,
|
|
IsOptional,
|
|
IsPostalCode,
|
|
IsString
|
|
} from "class-validator";
|
|
import { Column } from "typeorm";
|
|
import { config } from '../../config';
|
|
|
|
/**
|
|
* Defines the Address class.
|
|
* Implemented this way to prevent any formatting differences.
|
|
*/
|
|
export class Address {
|
|
/**
|
|
* 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({ nullable: true })
|
|
@IsString()
|
|
@IsOptional()
|
|
address2?: string;
|
|
|
|
/**
|
|
* The address's postal code.
|
|
* This will get checked against the postal code syntax for the configured country.
|
|
*/
|
|
@Column()
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
@IsPostalCode(config.postalcode_validation_countrycode)
|
|
postalcode: string;
|
|
|
|
/**
|
|
* The address's city.
|
|
*/
|
|
@Column()
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
city: string;
|
|
|
|
/**
|
|
* The address's country.
|
|
*/
|
|
@Column()
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
country: string;
|
|
|
|
/**
|
|
* Checks if this is a valid address
|
|
*/
|
|
public get isValidAddress(): Boolean {
|
|
if (!this.address1 || !this.city || !this.country || !this.postalcode) { return false; }
|
|
return true;
|
|
}
|
|
}
|