84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import {
|
|
IsEmail,
|
|
IsInt,
|
|
IsNotEmpty,
|
|
IsOptional,
|
|
IsPhoneNumber,
|
|
|
|
IsString
|
|
} from "class-validator";
|
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
|
|
import { config } from '../../config';
|
|
import { Address } from "./Address";
|
|
import { Donation } from "./Donation";
|
|
|
|
/**
|
|
* Defines the Participant entity.
|
|
* Participans can donate and therefor be associated with donation entities.
|
|
*/
|
|
@Entity()
|
|
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
|
export abstract class Participant {
|
|
/**
|
|
* Autogenerated unique id (primary key).
|
|
*/
|
|
@PrimaryGeneratedColumn()
|
|
@IsInt()
|
|
id: number;
|
|
|
|
/**
|
|
* The participant's first name.
|
|
*/
|
|
@Column()
|
|
@IsNotEmpty()
|
|
@IsString()
|
|
firstname: string;
|
|
|
|
/**
|
|
* The participant's middle name.
|
|
*/
|
|
@Column({ nullable: true })
|
|
@IsOptional()
|
|
@IsString()
|
|
middlename?: string;
|
|
|
|
/**
|
|
* The participant's last name.
|
|
*/
|
|
@Column()
|
|
@IsNotEmpty()
|
|
@IsString()
|
|
lastname: string;
|
|
|
|
/**
|
|
* The participant's address.
|
|
* This is a address object to prevent any formatting differences.
|
|
*/
|
|
@ManyToOne(() => Address, address => address.participants, { nullable: true })
|
|
address?: Address;
|
|
|
|
/**
|
|
* The participant's phone number.
|
|
* This will be validated against the configured country phone numer syntax (default: international).
|
|
*/
|
|
@Column({ nullable: true })
|
|
@IsOptional()
|
|
@IsPhoneNumber(config.phone_validation_countrycode)
|
|
phone?: string;
|
|
|
|
/**
|
|
* The participant's email address.
|
|
* Can be used to contact the participant.
|
|
*/
|
|
@Column({ nullable: true })
|
|
@IsOptional()
|
|
@IsEmail()
|
|
email?: string;
|
|
|
|
/**
|
|
* Used to link the participant as the donor of a donation.
|
|
* Attention: Only runner's can be associated as a distanceDonations distance source.
|
|
*/
|
|
@OneToMany(() => Donation, donation => donation.donor, { nullable: true })
|
|
donations: Donation[];
|
|
} |