Cleaned up a load of relations and optional stuff

ref #11
This commit is contained in:
2020-12-05 10:43:28 +01:00
parent 109e145a19
commit a1105f06ab
18 changed files with 50 additions and 80 deletions

View File

@@ -1,15 +1,14 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
import {
IsEmail,
IsInt,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
IsPositive,
IsString,
IsString
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Address } from "./Address";
import { Donation } from "./Donation";
import { RunnerGroup } from "./RunnerGroup";
/**
@@ -17,11 +16,10 @@ import { RunnerGroup } from "./RunnerGroup";
*/
@Entity()
export class GroupContact {
/**
* Autogenerated unique id (primary key).
*/
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
@@ -37,7 +35,7 @@ export class GroupContact {
* The contact's middle name.
* Optional
*/
@Column({nullable: true})
@Column({ nullable: true })
@IsOptional()
@IsString()
middlename?: string;
@@ -62,7 +60,7 @@ export class GroupContact {
* The contact's phone number.
* Optional
*/
@Column({nullable: true})
@Column({ nullable: true })
@IsOptional()
@IsPhoneNumber("DE")
phone?: string;
@@ -71,19 +69,13 @@ export class GroupContact {
* The contact's email address.
* Optional
*/
@Column({nullable: true})
@Column({ nullable: true })
@IsOptional()
@IsEmail()
email?: string;
/**
* Used to link the contact as the donor of a donation.
*/
@OneToMany(() => Donation, donation => donation.donor, { nullable: true })
donations: Donation[];
/**
* Used to link runners to donations.
* Used to link contacts to groups.
*/
@OneToMany(() => RunnerGroup, group => group.contact, { nullable: true })
groups: RunnerGroup[];