From ac0ce799f950dac194192177329d07c802feb457 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 17:40:03 +0100 Subject: [PATCH 1/2] Fixed the cirvular import BS ref #11 --- src/models/Donor.ts | 2 +- src/models/GroupContact.ts | 80 ++++++++++++++++++++++++++++++-- src/models/RunnerCard.ts | 2 +- src/models/RunnerGroup.ts | 6 --- src/models/RunnerOrganisation.ts | 9 +++- src/models/RunnerTeam.ts | 5 +- src/models/Scan.ts | 2 +- src/models/ScanStation.ts | 2 +- 8 files changed, 92 insertions(+), 16 deletions(-) diff --git a/src/models/Donor.ts b/src/models/Donor.ts index 0ed60da..db80082 100644 --- a/src/models/Donor.ts +++ b/src/models/Donor.ts @@ -13,5 +13,5 @@ export class Donor extends Participant { */ @Column() @IsBoolean() - receiptNeeded = false; + receiptNeeded: boolean; } \ No newline at end of file diff --git a/src/models/GroupContact.ts b/src/models/GroupContact.ts index 3ed4e63..58a07a7 100644 --- a/src/models/GroupContact.ts +++ b/src/models/GroupContact.ts @@ -1,12 +1,86 @@ -import { Entity, OneToMany } from "typeorm"; -import { Participant } from "./Participant"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm"; +import { + IsEmail, + IsInt, + IsNotEmpty, + IsOptional, + IsPhoneNumber, + IsString, +} from "class-validator"; +import { Address } from "./Address"; +import { Donation } from "./Donation"; import { RunnerGroup } from "./RunnerGroup"; /** * Defines a group's contact. */ @Entity() -export class GroupContact extends Participant{ +export class GroupContact { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The contact's first name. + */ + @Column() + @IsNotEmpty() + @IsString() + firstname: string; + + /** + * The contact's middle name. + * Optional + */ + @Column() + @IsOptional() + @IsString() + middlename?: string; + + /** + * The contact's last name. + */ + @Column() + @IsOptional() + @IsString() + lastname: string; + + /** + * The contact's address. + * Optional + */ + @IsOptional() + @ManyToOne(() => Address, address => address.participants) + address?: Address; + + /** + * The contact's phone number. + * Optional + */ + @Column() + @IsOptional() + @IsPhoneNumber("DE") + phone?: string; + + /** + * The contact's email address. + * Optional + */ + @Column() + @IsOptional() + @IsEmail() + email?: string; + + /** + * Used to link the contact as the donor of a donation. + */ + @OneToMany(() => Donation, donation => donation.donor) + donations: Donation[]; + /** * Used to link runners to donations. */ diff --git a/src/models/RunnerCard.ts b/src/models/RunnerCard.ts index e751506..2796f4c 100644 --- a/src/models/RunnerCard.ts +++ b/src/models/RunnerCard.ts @@ -45,7 +45,7 @@ export class RunnerCard { */ @Column() @IsBoolean() - enabled = true; + enabled: boolean; /** * Used to link cards to a track scans. diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index 52f478f..a7c199b 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -43,10 +43,4 @@ export abstract class RunnerGroup { */ @OneToMany(() => Runner, runner => runner.group) runners: Runner[]; - - /** - * Used to link teams to runner groups. - */ - @OneToMany(() => RunnerTeam, team => team.parentGroup) - teams: RunnerTeam[]; } \ No newline at end of file diff --git a/src/models/RunnerOrganisation.ts b/src/models/RunnerOrganisation.ts index 22fe8a5..958b363 100644 --- a/src/models/RunnerOrganisation.ts +++ b/src/models/RunnerOrganisation.ts @@ -1,7 +1,8 @@ -import { Entity, Column, ManyToOne } from "typeorm"; +import { Entity, Column, ManyToOne, OneToMany } from "typeorm"; import { IsOptional,} from "class-validator"; import { RunnerGroup } from "./RunnerGroup"; import { Address } from "./Address"; +import { RunnerTeam } from "./RunnerTeam"; /** * Defines a runner organisation (business or school for example). @@ -16,4 +17,10 @@ export class RunnerOrganisation extends RunnerGroup { @IsOptional() @ManyToOne(() => Address, address => address.groups) address?: Address; + + /** + * Used to link teams to runner groups. + */ + @OneToMany(() => RunnerTeam, team => team.parentGroup) + teams: RunnerTeam[]; } \ No newline at end of file diff --git a/src/models/RunnerTeam.ts b/src/models/RunnerTeam.ts index e716e27..f12c5eb 100644 --- a/src/models/RunnerTeam.ts +++ b/src/models/RunnerTeam.ts @@ -1,6 +1,7 @@ import { Entity, Column, ManyToOne } from "typeorm"; import { IsNotEmpty } from "class-validator"; import { RunnerGroup } from "./RunnerGroup"; +import { RunnerOrganisation } from "./RunnerOrganisation"; /** * Defines a runner team (class or deparment for example). @@ -13,6 +14,6 @@ export class RunnerTeam extends RunnerGroup { * Optional */ @IsNotEmpty() - @ManyToOne(() => RunnerGroup, group => group.teams) - parentGroup?: RunnerGroup; + @ManyToOne(() => RunnerOrganisation, org => org.teams) + parentGroup?: RunnerOrganisation; } \ No newline at end of file diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 6c2dccc..db41242 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -40,5 +40,5 @@ export abstract class Scan { */ @Column() @IsBoolean() - valid = true; + valid: boolean; } diff --git a/src/models/ScanStation.ts b/src/models/ScanStation.ts index c89a3a4..4cd0246 100644 --- a/src/models/ScanStation.ts +++ b/src/models/ScanStation.ts @@ -50,7 +50,7 @@ export class ScanStation { */ @Column() @IsBoolean() - enabled = true; + enabled: boolean; /** * Used to link track scans to a scan station. From 932e782a14454a05aa59f9b76c7c9638aa440385 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 18:05:18 +0100 Subject: [PATCH 2/2] Added defaults back in --- src/models/Donor.ts | 4 ++-- src/models/RunnerCard.ts | 3 ++- src/models/Scan.ts | 3 ++- src/models/ScanStation.ts | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/models/Donor.ts b/src/models/Donor.ts index db80082..5d0af07 100644 --- a/src/models/Donor.ts +++ b/src/models/Donor.ts @@ -9,9 +9,9 @@ import { Participant } from "./Participant"; export class Donor extends Participant { /** * Does this donor need a receipt?. - * Default: True + * Default: false */ @Column() @IsBoolean() - receiptNeeded: boolean; + receiptNeeded: boolean = false; } \ No newline at end of file diff --git a/src/models/RunnerCard.ts b/src/models/RunnerCard.ts index 2796f4c..f978d0c 100644 --- a/src/models/RunnerCard.ts +++ b/src/models/RunnerCard.ts @@ -42,10 +42,11 @@ export class RunnerCard { /** * Is the card enabled (for fraud reasons)? + * Default: true */ @Column() @IsBoolean() - enabled: boolean; + enabled: boolean = true; /** * Used to link cards to a track scans. diff --git a/src/models/Scan.ts b/src/models/Scan.ts index db41242..055e94b 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -37,8 +37,9 @@ export abstract class Scan { /** * Is the scan valid (for fraud reasons). + * Default: true */ @Column() @IsBoolean() - valid: boolean; + valid: boolean = true; } diff --git a/src/models/ScanStation.ts b/src/models/ScanStation.ts index 4cd0246..4415ebc 100644 --- a/src/models/ScanStation.ts +++ b/src/models/ScanStation.ts @@ -47,10 +47,11 @@ export class ScanStation { /** * Is the station enabled (for fraud reasons)? + * Default: true */ @Column() @IsBoolean() - enabled: boolean; + enabled: boolean = true; /** * Used to link track scans to a scan station.