From abb7f7f89452cdd44bbc5f34d377a9306684fc9b Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:10:17 +0100 Subject: [PATCH 01/53] Added Basic Scan interface ref #11 --- src/models/IScan.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/models/IScan.ts diff --git a/src/models/IScan.ts b/src/models/IScan.ts new file mode 100644 index 0000000..6906c5c --- /dev/null +++ b/src/models/IScan.ts @@ -0,0 +1,19 @@ +/** + * Defines the scan interface. +*/ +export interface IScan { + /** + * Autogenerated unique id (primary key). + */ + id: number; + + /** + * The associated runner. + */ + runner: Runner; + + /** + * The scan's distance in meters. + */ + distance: number; +} From a2cf8d1f2c4a2087e2dd6c297bea1a46db4220f9 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:16:50 +0100 Subject: [PATCH 02/53] Switched from implementing the "interfaces" as interface to abstract classes ref #11 This was done to take advantage of typeorm and class validator --- src/models/IScan.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/models/IScan.ts b/src/models/IScan.ts index 6906c5c..fdd6541 100644 --- a/src/models/IScan.ts +++ b/src/models/IScan.ts @@ -1,19 +1,35 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsPositive, +} from "class-validator"; + /** * Defines the scan interface. */ -export interface IScan { +export abstract class IScan { /** * Autogenerated unique id (primary key). */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() id: number; /** * The associated runner. */ + @Column() + @IsNotEmpty() runner: Runner; /** * The scan's distance in meters. */ + @Column() + @IsInt() + @IsPositive() distance: number; } From f350007ae5696a16ecb1994bf3b4be843781b91d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:20:43 +0100 Subject: [PATCH 03/53] Added participant abstract class ref #11 --- src/models/IParticipant.ts | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/models/IParticipant.ts diff --git a/src/models/IParticipant.ts b/src/models/IParticipant.ts new file mode 100644 index 0000000..440e5e2 --- /dev/null +++ b/src/models/IParticipant.ts @@ -0,0 +1,73 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsEmail, + IsInt, + IsNotEmpty, + IsOptional, + IsPhoneNumber, + IsString, +} from "class-validator"; + +/** + * Defines the participant interface. +*/ +export abstract class IParticipant { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The participant's first name. + */ + @Column() + @IsNotEmpty() + @IsString() + firstname: string; + + /** + * The participant's middle name. + * Optional + */ + @Column() + @IsOptional() + @IsString() + middlename?: string; + + /** + * The participant's last name. + */ + @Column() + @IsOptional() + @IsString() + lastname: string; + + /** + * The participant's address. + * Optional + */ + @Column() + @IsOptional() + address?: Location; + + /** + * The participant's phone number. + * Optional + */ + @Column() + @IsOptional() + @IsPhoneNumber("DE") + phone?: string; + + /** + * The participant's email address. + * Optional + */ + @Column() + @IsOptional() + @IsEmail() + email?: string; +} From f8e1bf715b57788c16c8f8565bc20696c26b1499 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:21:44 +0100 Subject: [PATCH 04/53] Changed nameing scheme for the abstract classes since we're not useing interfaces ref #11 --- src/models/{IParticipant.ts => Participant.ts} | 4 ++-- src/models/{IScan.ts => Scan.ts} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/models/{IParticipant.ts => Participant.ts} (96%) rename src/models/{IScan.ts => Scan.ts} (94%) diff --git a/src/models/IParticipant.ts b/src/models/Participant.ts similarity index 96% rename from src/models/IParticipant.ts rename to src/models/Participant.ts index 440e5e2..551aeec 100644 --- a/src/models/IParticipant.ts +++ b/src/models/Participant.ts @@ -11,7 +11,7 @@ import { /** * Defines the participant interface. */ -export abstract class IParticipant { +export abstract class Participant { /** * Autogenerated unique id (primary key). */ @@ -70,4 +70,4 @@ export abstract class IParticipant { @IsOptional() @IsEmail() email?: string; -} +} \ No newline at end of file diff --git a/src/models/IScan.ts b/src/models/Scan.ts similarity index 94% rename from src/models/IScan.ts rename to src/models/Scan.ts index fdd6541..dce9230 100644 --- a/src/models/IScan.ts +++ b/src/models/Scan.ts @@ -9,7 +9,7 @@ import { /** * Defines the scan interface. */ -export abstract class IScan { +export abstract class Scan { /** * Autogenerated unique id (primary key). */ From f999c416c4367ddbb99fe19e443c1ce4867f5053 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:27:18 +0100 Subject: [PATCH 05/53] Added Runnergroup abstract class ref #11 --- src/models/RunnerGroup.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/models/RunnerGroup.ts diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts new file mode 100644 index 0000000..d5223bb --- /dev/null +++ b/src/models/RunnerGroup.ts @@ -0,0 +1,38 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsEmail, + IsInt, + IsNotEmpty, + IsOptional, + IsPhoneNumber, + IsString, +} from "class-validator"; + +/** + * Defines the runnerGroup interface. +*/ +export abstract class RunnerGroup { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The group's first name. + */ + @Column() + @IsNotEmpty() + @IsString() + name: string; + + /** + * The participant's middle name. + * Optional + */ + @Column() + @IsOptional() + contact?: GroupContact; +} \ No newline at end of file From 72f80859a974086ba354b48058844d12def937dd Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:27:48 +0100 Subject: [PATCH 06/53] Added todo's for relationships --- src/models/Participant.ts | 1 + src/models/RunnerGroup.ts | 1 + src/models/Scan.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 551aeec..0d4ebed 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -51,6 +51,7 @@ export abstract class Participant { */ @Column() @IsOptional() + //TODO: Relationship address?: Location; /** diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index d5223bb..e074b29 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -34,5 +34,6 @@ export abstract class RunnerGroup { */ @Column() @IsOptional() + //TODO: Relationship contact?: GroupContact; } \ No newline at end of file diff --git a/src/models/Scan.ts b/src/models/Scan.ts index dce9230..e1951db 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -23,6 +23,7 @@ export abstract class Scan { */ @Column() @IsNotEmpty() + //TODO: Relationship runner: Runner; /** From 57ba0c3051ac539eca96a9d32faa00a910332db3 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:31:05 +0100 Subject: [PATCH 07/53] Added the donation abstract/interface --- src/models/Donation.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/models/Donation.ts diff --git a/src/models/Donation.ts b/src/models/Donation.ts new file mode 100644 index 0000000..82897c8 --- /dev/null +++ b/src/models/Donation.ts @@ -0,0 +1,37 @@ +import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsPositive, +} from "class-validator"; +import { Participant } from "./Participant"; + +/** + * Defines the donation interface. +*/ +export abstract class Donation { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The donations's donor. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + donor: Participant; + + /** + * The donation's amount in cents (or whatever your currency's smallest unit is.). + */ + @Column() + @IsInt() + @IsPositive() + amount: number; +} \ No newline at end of file From 748fff5c323c63cdfe0c8e9260ca175d99194a6b Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:32:21 +0100 Subject: [PATCH 08/53] Cleaned up imports and descriptions ref #11 --- src/models/Participant.ts | 2 +- src/models/RunnerGroup.ts | 6 ++---- src/models/Scan.ts | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 0d4ebed..ca8f2ec 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column } from "typeorm"; import { IsEmail, IsInt, diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index e074b29..e7d8ecf 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -1,10 +1,8 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column } from "typeorm"; import { - IsEmail, IsInt, IsNotEmpty, IsOptional, - IsPhoneNumber, IsString, } from "class-validator"; @@ -29,7 +27,7 @@ export abstract class RunnerGroup { name: string; /** - * The participant's middle name. + * The group's contact. * Optional */ @Column() diff --git a/src/models/Scan.ts b/src/models/Scan.ts index e1951db..9c056f2 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column } from "typeorm"; import { IsInt, IsNotEmpty, From 5a04e61d1cb1583e2e496fbfcb5ba78c5be6dea1 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:38:28 +0100 Subject: [PATCH 09/53] Added the runner class ref #11 --- src/models/Runner.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/models/Runner.ts diff --git a/src/models/Runner.ts b/src/models/Runner.ts new file mode 100644 index 0000000..3c9cec2 --- /dev/null +++ b/src/models/Runner.ts @@ -0,0 +1,18 @@ +import { Entity, Column } from "typeorm"; +import { IsNotEmpty,} from "class-validator"; +import { Participant } from "./Participant"; +import { RunnerGroup } from "./RunnerGroup"; + +/** + * Defines a runner. +*/ +@Entity() +export class Track extends Participant { + /** + * The runner's associated group. + */ + @Column() + @IsNotEmpty() + //TODO:Relation + group: RunnerGroup; +} From 7ce8c375a2cf6aceab827d69aaa9b2835a71a5f6 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:39:03 +0100 Subject: [PATCH 10/53] Fixed copy-paste slip up ref #11 --- src/models/Runner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/Runner.ts b/src/models/Runner.ts index 3c9cec2..a625333 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -7,7 +7,7 @@ import { RunnerGroup } from "./RunnerGroup"; * Defines a runner. */ @Entity() -export class Track extends Participant { +export class Runner extends Participant { /** * The runner's associated group. */ From b632c09924bd3f1f42bfc0d3ed820d349576b13a Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:41:56 +0100 Subject: [PATCH 11/53] Added donor ref #11 --- src/models/Donor.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/models/Donor.ts diff --git a/src/models/Donor.ts b/src/models/Donor.ts new file mode 100644 index 0000000..0ed60da --- /dev/null +++ b/src/models/Donor.ts @@ -0,0 +1,17 @@ +import { Entity, Column } from "typeorm"; +import { IsBoolean } from "class-validator"; +import { Participant } from "./Participant"; + +/** + * Defines a donor. +*/ +@Entity() +export class Donor extends Participant { + /** + * Does this donor need a receipt?. + * Default: True + */ + @Column() + @IsBoolean() + receiptNeeded = false; +} \ No newline at end of file From daea0568a8da9dd661779510ab328175d6f790f2 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:45:59 +0100 Subject: [PATCH 12/53] Amount no longer is a column by default --- src/models/Donation.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/models/Donation.ts b/src/models/Donation.ts index 82897c8..3ccdafc 100644 --- a/src/models/Donation.ts +++ b/src/models/Donation.ts @@ -29,9 +29,8 @@ export abstract class Donation { /** * The donation's amount in cents (or whatever your currency's smallest unit is.). + * The exact implementation may differ for each type of donation. */ - @Column() @IsInt() - @IsPositive() amount: number; } \ No newline at end of file From a8d1ec6f9b3a3a4673945de9143b299cac1933f8 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:50:43 +0100 Subject: [PATCH 13/53] Marked amount as abstract ref #11 --- src/models/Donation.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/models/Donation.ts b/src/models/Donation.ts index 3ccdafc..87f4e80 100644 --- a/src/models/Donation.ts +++ b/src/models/Donation.ts @@ -31,6 +31,5 @@ export abstract class Donation { * The donation's amount in cents (or whatever your currency's smallest unit is.). * The exact implementation may differ for each type of donation. */ - @IsInt() - amount: number; + abstract amount: number; } \ No newline at end of file From 6c32a9ebe954cd272ee140d06ef2553c9091239e Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:51:30 +0100 Subject: [PATCH 14/53] Added distance Donation --- src/models/DistanceDonation.ts | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/models/DistanceDonation.ts diff --git a/src/models/DistanceDonation.ts b/src/models/DistanceDonation.ts new file mode 100644 index 0000000..59e0f62 --- /dev/null +++ b/src/models/DistanceDonation.ts @@ -0,0 +1,42 @@ +import { Entity, Column } from "typeorm"; +import { IsInt, IsNotEmpty, IsPositive,} from "class-validator"; +import { Donation } from "./Donation"; +import { Runner } from "./Runner"; + +/** + * Defines a distance based donation. + * Here people donate a certain amout per kilometer +*/ +@Entity() +export class DistanceDonation extends Donation { + /** + * The runner associated. + */ + @Column() + @IsNotEmpty() + //TODO:Relation + runner: Runner; + + /** + * The amount the donor set to be donated per kilometer that the runner ran. + */ + @Column() + @IsInt() + @IsPositive() + amountPerDistance: number; + + /** + * The donation's amount in cents (or whatever your currency's smallest unit is.). + * The exact implementation may differ for each type of donation. + */ + @IsInt() + public get amount(): number { + let calculatedAmount = -1; + try { + calculatedAmount = this.amountPerDistance * this.runner.getDistance(); + } catch (error) { + throw error; + } + return calculatedAmount; + } +} From deae0bb84b02b2ddf18104b7e3181c05cf20ec35 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:53:43 +0100 Subject: [PATCH 15/53] Added finxed donations ref #11 --- src/models/FixedDonation.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/models/FixedDonation.ts diff --git a/src/models/FixedDonation.ts b/src/models/FixedDonation.ts new file mode 100644 index 0000000..e429ddf --- /dev/null +++ b/src/models/FixedDonation.ts @@ -0,0 +1,18 @@ +import { Entity, Column } from "typeorm"; +import { IsInt, IsPositive,} from "class-validator"; +import { Donation } from "./Donation"; + +/** + * Defines a fixed donation. +*/ +@Entity() +export class FixedDonation extends Donation { + + /** + * The donation's amount in cents (or whatever your currency's smallest unit is.). + */ + @Column() + @IsInt() + @IsPositive() + amount: number; +} \ No newline at end of file From 66f7a7928c60ff6def7da2c7238de297d03d67e1 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 17:58:23 +0100 Subject: [PATCH 16/53] Added the runner org class ref #11 --- src/models/RunnerOrganisation.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/models/RunnerOrganisation.ts diff --git a/src/models/RunnerOrganisation.ts b/src/models/RunnerOrganisation.ts new file mode 100644 index 0000000..346d75a --- /dev/null +++ b/src/models/RunnerOrganisation.ts @@ -0,0 +1,19 @@ +import { Entity, Column } from "typeorm"; +import { IsOptional,} from "class-validator"; +import { RunnerGroup } from "./RunnerGroup"; + +/** + * Defines a runner organisation (business or school for example). +*/ +@Entity() +export class RunnerOrganisation extends RunnerGroup { + + /** + * The organisations's address. + * Optional + */ + @Column() + @IsOptional() + //TODO: Relationship + address?: Location; +} \ No newline at end of file From ac40527fa2997450f2e0685485bc7d91ca3e9bde Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:01:32 +0100 Subject: [PATCH 17/53] Added the runnerteam class ref #11 --- src/models/RunnerTeam.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/models/RunnerTeam.ts diff --git a/src/models/RunnerTeam.ts b/src/models/RunnerTeam.ts new file mode 100644 index 0000000..204bc01 --- /dev/null +++ b/src/models/RunnerTeam.ts @@ -0,0 +1,19 @@ +import { Entity, Column } from "typeorm"; +import { IsNotEmpty } from "class-validator"; +import { RunnerGroup } from "./RunnerGroup"; + +/** + * Defines a runner team (class or deparment for example). +*/ +@Entity() +export class RunnerTeam extends RunnerGroup { + + /** + * The team's parent group. + * Optional + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + parentGroup?: RunnerGroup; +} \ No newline at end of file From 96d70d5048b89324266f33468ab3a3ea4c771604 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:07:39 +0100 Subject: [PATCH 18/53] Added group contact class ref #11 --- src/models/GroupContact.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/models/GroupContact.ts diff --git a/src/models/GroupContact.ts b/src/models/GroupContact.ts new file mode 100644 index 0000000..e243d00 --- /dev/null +++ b/src/models/GroupContact.ts @@ -0,0 +1,8 @@ +import { Entity } from "typeorm"; +import { Participant } from "./Participant"; + +/** + * Defines a group's contact. +*/ +@Entity() +export class GroupContact extends Participant{} \ No newline at end of file From fbbb5df64f6033c528c7e20141fd3208b103500f Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:16:17 +0100 Subject: [PATCH 19/53] Added runnerCard class ref #11 --- src/models/RunnerCard.ts | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/models/RunnerCard.ts diff --git a/src/models/RunnerCard.ts b/src/models/RunnerCard.ts new file mode 100644 index 0000000..09b3746 --- /dev/null +++ b/src/models/RunnerCard.ts @@ -0,0 +1,49 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsBoolean, + IsInt, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; +import { Runner } from "./Runner"; + +/** + * Defines a card that can be scanned via a scanner station. +*/ +@Entity() +export class RunnerCard { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The runner that is currently associated with this card. + */ + @Column() + @IsOptional() + //TODO: Relation + runner: Runner; + + /** + * The card's code. + * This has to be able to being converted to something barcode compatible. + * Probably gonna be autogenerated. + */ + @Column() + @IsString() + @IsNotEmpty() + //TODO: Generate this + code: string; + + /** + * Is the card enabled (for fraud reasons)? + */ + @Column() + @IsBoolean() + enabled = true; +} From f7beebce3f5dc39f6b5e8ae34a1010ebf25058e1 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:39:33 +0100 Subject: [PATCH 20/53] Added scanstation class ref #11 --- src/models/ScanStation.ts | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/models/ScanStation.ts diff --git a/src/models/ScanStation.ts b/src/models/ScanStation.ts new file mode 100644 index 0000000..2989be0 --- /dev/null +++ b/src/models/ScanStation.ts @@ -0,0 +1,54 @@ +import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsBoolean, + IsInt, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; +import { Track } from "./Track"; + +/** + * ScannerStations have the ability to create scans for specific tracks. +*/ +@Entity() +export class ScanStation { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The station's description. + */ + @Column() + @IsNotEmpty() + @IsString() + description: string; + + /** + * The track this station is associated with. + */ + @Column() + @IsNotEmpty() + //TODO: Relation + track: Track; + + /** + * The station's api key. + */ + @Column() + @IsNotEmpty() + @IsString() + key: string; + + /** + * Is the station enabled (for fraud reasons)? + */ + @Column() + @IsBoolean() + enabled = true; +} From 79eecbb329c1f7181558d8a2fc39b91179ec91cf Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:48:28 +0100 Subject: [PATCH 21/53] fixxed missing imports and commented out a non-implemented function call ref #11 --- src/models/DistanceDonation.ts | 2 +- src/models/RunnerGroup.ts | 1 + src/models/Scan.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/models/DistanceDonation.ts b/src/models/DistanceDonation.ts index 59e0f62..d30b093 100644 --- a/src/models/DistanceDonation.ts +++ b/src/models/DistanceDonation.ts @@ -33,7 +33,7 @@ export class DistanceDonation extends Donation { public get amount(): number { let calculatedAmount = -1; try { - calculatedAmount = this.amountPerDistance * this.runner.getDistance(); + //calculatedAmount = this.amountPerDistance * this.runner.getDistance(); } catch (error) { throw error; } diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index e7d8ecf..08ea35d 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -5,6 +5,7 @@ import { IsOptional, IsString, } from "class-validator"; +import { GroupContact } from "./GroupContact"; /** * Defines the runnerGroup interface. diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 9c056f2..d59e0f5 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -5,6 +5,7 @@ import { IsOptional, IsPositive, } from "class-validator"; +import { Runner } from "./Runner"; /** * Defines the scan interface. From 084e2d99303ebf02f69782e647ce964649156d07 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:50:06 +0100 Subject: [PATCH 22/53] Renamed property, so it fits with the rest of the nameing ref #11 --- src/models/Track.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/Track.ts b/src/models/Track.ts index ea09063..d5aeaa5 100644 --- a/src/models/Track.ts +++ b/src/models/Track.ts @@ -29,10 +29,10 @@ export class Track { name: string; /** - * The track's length in meters. + * The track's length/distance in meters. */ @Column() @IsInt() @IsPositive() - length: number; + distance: number; } From df3715d8d67ea2506d541fe2418cd1a5bff77e8f Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:57:34 +0100 Subject: [PATCH 23/53] Changed the distance to be an abstract ref #11 --- src/models/Scan.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/models/Scan.ts b/src/models/Scan.ts index d59e0f5..3991b7a 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -30,8 +30,7 @@ export abstract class Scan { /** * The scan's distance in meters. */ - @Column() @IsInt() @IsPositive() - distance: number; + abstract distance: number; } From 8b2d6840a861d44132740fa65128d45400ebd449 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:57:44 +0100 Subject: [PATCH 24/53] Added the track scan class ref #11 --- src/models/TrackScan.ts | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/models/TrackScan.ts diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts new file mode 100644 index 0000000..c7bc0b9 --- /dev/null +++ b/src/models/TrackScan.ts @@ -0,0 +1,83 @@ +import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsBoolean, + IsDateString, + IsInt, + IsNotEmpty, + IsOptional, + IsPositive, +} from "class-validator"; +import { Scan } from "./Scan"; +import { Runner } from "./Runner"; +import { Track } from "./Track"; +import { RunnerCard } from "./RunnerCard"; +import { ScanStation } from "./ScanStation"; + +/** + * Defines the scan interface. +*/ +export class TrackScan extends Scan { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The associated runner. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + runner: Runner; + + /** + * The associated track. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + track: Track; + + /** + * The associated card. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + card: RunnerCard; + + /** + * The scanning station. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + station: ScanStation; + + /** + * The scan's distance in meters. + */ + @IsInt() + @IsPositive() + public get distance(): number { + return this.track.distance; + } + + /** + * The scan's creation timestamp. + */ + @Column() + @IsDateString() + @IsNotEmpty() + timestamp: string; + + /** + * Is the scan valid (for fraud reasons). + */ + @Column() + @IsBoolean() + valid = true; +} From 2bd0cbadbed6b04136d7fc3c6f0f5e8ef35d982d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:03:41 +0100 Subject: [PATCH 25/53] 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; +} From dca9aef25842b6127e258475039d6c2e1bad99f7 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:06:56 +0100 Subject: [PATCH 26/53] Other classed are now using the new Address class rather than the old location placeholder ref #11 --- src/models/Participant.ts | 3 ++- src/models/RunnerOrganisation.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/models/Participant.ts b/src/models/Participant.ts index ca8f2ec..2b356a3 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -7,6 +7,7 @@ import { IsPhoneNumber, IsString, } from "class-validator"; +import { Address } from "./Address"; /** * Defines the participant interface. @@ -52,7 +53,7 @@ export abstract class Participant { @Column() @IsOptional() //TODO: Relationship - address?: Location; + address?: Address; /** * The participant's phone number. diff --git a/src/models/RunnerOrganisation.ts b/src/models/RunnerOrganisation.ts index 346d75a..3166964 100644 --- a/src/models/RunnerOrganisation.ts +++ b/src/models/RunnerOrganisation.ts @@ -1,6 +1,7 @@ import { Entity, Column } from "typeorm"; import { IsOptional,} from "class-validator"; import { RunnerGroup } from "./RunnerGroup"; +import { Address } from "./Address"; /** * Defines a runner organisation (business or school for example). @@ -15,5 +16,5 @@ export class RunnerOrganisation extends RunnerGroup { @Column() @IsOptional() //TODO: Relationship - address?: Location; + address?: Address; } \ No newline at end of file From 1c43442300b9287ed7148a0847bf1db7805e7f0b Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:10:52 +0100 Subject: [PATCH 27/53] Relations for distanceDonation ref #11 --- src/models/DistanceDonation.ts | 6 +++--- src/models/Runner.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/models/DistanceDonation.ts b/src/models/DistanceDonation.ts index d30b093..915362b 100644 --- a/src/models/DistanceDonation.ts +++ b/src/models/DistanceDonation.ts @@ -1,4 +1,4 @@ -import { Entity, Column } from "typeorm"; +import { Entity, Column, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, IsPositive,} from "class-validator"; import { Donation } from "./Donation"; import { Runner } from "./Runner"; @@ -14,7 +14,7 @@ export class DistanceDonation extends Donation { */ @Column() @IsNotEmpty() - //TODO:Relation + @ManyToOne(() => Runner, runner => runner.distanceDonations) runner: Runner; /** @@ -33,7 +33,7 @@ export class DistanceDonation extends Donation { public get amount(): number { let calculatedAmount = -1; try { - //calculatedAmount = this.amountPerDistance * this.runner.getDistance(); + calculatedAmount = this.amountPerDistance * this.runner.getDistance(); } catch (error) { throw error; } diff --git a/src/models/Runner.ts b/src/models/Runner.ts index a625333..21af21a 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -1,7 +1,8 @@ -import { Entity, Column } from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { IsNotEmpty,} from "class-validator"; import { Participant } from "./Participant"; import { RunnerGroup } from "./RunnerGroup"; +import { DistanceDonation } from "./DistanceDonation"; /** * Defines a runner. @@ -15,4 +16,7 @@ export class Runner extends Participant { @IsNotEmpty() //TODO:Relation group: RunnerGroup; + + @OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner) + distanceDonations: DistanceDonation[]; } From 2b693917b0d003165bed24d97d9218f5dc613d18 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:13:56 +0100 Subject: [PATCH 28/53] Added relationships for donation ref #11 --- src/models/Donation.ts | 4 ++-- src/models/Participant.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/Donation.ts b/src/models/Donation.ts index 87f4e80..f7ea19c 100644 --- a/src/models/Donation.ts +++ b/src/models/Donation.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, @@ -24,7 +24,7 @@ export abstract class Donation { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => Participant, donor => donor.donations) donor: Participant; /** diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 2b356a3..1a8c245 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; import { IsEmail, IsInt, @@ -8,6 +8,7 @@ import { IsString, } from "class-validator"; import { Address } from "./Address"; +import { Donation } from "./Donation"; /** * Defines the participant interface. @@ -72,4 +73,10 @@ export abstract class Participant { @IsOptional() @IsEmail() email?: string; + + /** + * Used to link the participant as the donor of a donation. + */ + @OneToMany(() => Donation, donation => donation.donor) + donations: Donation[]; } \ No newline at end of file From 40752761302a043e8c974fe98bc57a865eedcb55 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:17:53 +0100 Subject: [PATCH 29/53] Added relations for participants ref #11 --- src/models/Address.ts | 9 ++++++++- src/models/Participant.ts | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/Address.ts b/src/models/Address.ts index df8e2ca..723bac9 100644 --- a/src/models/Address.ts +++ b/src/models/Address.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; import { IsInt, IsNotEmpty, @@ -6,6 +6,7 @@ import { IsPostalCode, IsString, } from "class-validator"; +import { Participant } from "./Participant"; /** * Defines a address (to be used for contact information). @@ -70,4 +71,10 @@ export class Address { @IsString() @IsNotEmpty() country: string; + + /** + * Used to link the address to participants. + */ + @OneToMany(() => Participant, participant => participant.address) + participants: Participant[]; } diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 1a8c245..e70e14e 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm"; import { IsEmail, IsInt, @@ -53,7 +53,7 @@ export abstract class Participant { */ @Column() @IsOptional() - //TODO: Relationship + @ManyToOne(() => Address, address => address.participants) address?: Address; /** From a6222a80251168153dd82b69a9eb65be87aaf3a8 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:20:27 +0100 Subject: [PATCH 30/53] Added relations for runners ref #11 --- src/models/Runner.ts | 7 +++++-- src/models/RunnerGroup.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/models/Runner.ts b/src/models/Runner.ts index 21af21a..49ce643 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany } from "typeorm"; +import { Entity, Column, OneToMany, ManyToOne } from "typeorm"; import { IsNotEmpty,} from "class-validator"; import { Participant } from "./Participant"; import { RunnerGroup } from "./RunnerGroup"; @@ -14,9 +14,12 @@ export class Runner extends Participant { */ @Column() @IsNotEmpty() - //TODO:Relation + @ManyToOne(() => RunnerGroup, group => group.runners) group: RunnerGroup; + /** + * Used to link runners to donations. + */ @OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner) distanceDonations: DistanceDonation[]; } diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index 08ea35d..d619e2f 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; import { IsInt, IsNotEmpty, @@ -6,6 +6,7 @@ import { IsString, } from "class-validator"; import { GroupContact } from "./GroupContact"; +import { Runner } from "./Runner"; /** * Defines the runnerGroup interface. @@ -35,4 +36,10 @@ export abstract class RunnerGroup { @IsOptional() //TODO: Relationship contact?: GroupContact; + + /** + * Used to link runners to a runner group. + */ + @OneToMany(() => Runner, runner => runner.group) + runners: Runner[]; } \ No newline at end of file From 029e4beaf545b2dacaeb272da7f0776cfc28b82d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:27:36 +0100 Subject: [PATCH 31/53] Added relations for runner cards ref #11 --- src/models/Runner.ts | 7 +++++++ src/models/RunnerCard.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/models/Runner.ts b/src/models/Runner.ts index 49ce643..3db90fc 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -3,6 +3,7 @@ import { IsNotEmpty,} from "class-validator"; import { Participant } from "./Participant"; import { RunnerGroup } from "./RunnerGroup"; import { DistanceDonation } from "./DistanceDonation"; +import { RunnerCard } from "./RunnerCard"; /** * Defines a runner. @@ -22,4 +23,10 @@ export class Runner extends Participant { */ @OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner) distanceDonations: DistanceDonation[]; + + /** + * Used to link runners to cards. + */ + @OneToMany(() => RunnerCard, card => card.runner) + cards: RunnerCard[]; } diff --git a/src/models/RunnerCard.ts b/src/models/RunnerCard.ts index 09b3746..151f58c 100644 --- a/src/models/RunnerCard.ts +++ b/src/models/RunnerCard.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { IsBoolean, IsInt, @@ -26,7 +26,7 @@ export class RunnerCard { */ @Column() @IsOptional() - //TODO: Relation + @ManyToOne(() => Runner, runner => runner.cards) runner: Runner; /** From f28b08ed654309305960f8f5a882b2f6d492bf1d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:44:51 +0100 Subject: [PATCH 32/53] Added relations to RunnerGroup ref #11 --- src/models/GroupContact.ts | 11 +++++++++-- src/models/RunnerGroup.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/models/GroupContact.ts b/src/models/GroupContact.ts index e243d00..3ed4e63 100644 --- a/src/models/GroupContact.ts +++ b/src/models/GroupContact.ts @@ -1,8 +1,15 @@ -import { Entity } from "typeorm"; +import { Entity, OneToMany } from "typeorm"; import { Participant } from "./Participant"; +import { RunnerGroup } from "./RunnerGroup"; /** * Defines a group's contact. */ @Entity() -export class GroupContact extends Participant{} \ No newline at end of file +export class GroupContact extends Participant{ + /** + * Used to link runners to donations. + */ + @OneToMany(() => RunnerGroup, group => group.contact) + groups: RunnerGroup[]; +} \ No newline at end of file diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index d619e2f..c35ad48 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, @@ -34,7 +34,7 @@ export abstract class RunnerGroup { */ @Column() @IsOptional() - //TODO: Relationship + @ManyToOne(() => GroupContact, contact => contact.groups) contact?: GroupContact; /** From 7ac46a7cc75618f5c01c46d3baee83c30d124124 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:48:20 +0100 Subject: [PATCH 33/53] Added relations to RunnerOrganisation --- src/models/Address.ts | 7 +++++++ src/models/RunnerOrganisation.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/models/Address.ts b/src/models/Address.ts index 723bac9..59e6570 100644 --- a/src/models/Address.ts +++ b/src/models/Address.ts @@ -7,6 +7,7 @@ import { IsString, } from "class-validator"; import { Participant } from "./Participant"; +import { RunnerOrganisation } from "./RunnerOrganisation"; /** * Defines a address (to be used for contact information). @@ -77,4 +78,10 @@ export class Address { */ @OneToMany(() => Participant, participant => participant.address) participants: Participant[]; + + /** + * Used to link the address to runner groups. + */ + @OneToMany(() => RunnerOrganisation, group => group.address) + groups: RunnerOrganisation[]; } diff --git a/src/models/RunnerOrganisation.ts b/src/models/RunnerOrganisation.ts index 3166964..d3e4ea8 100644 --- a/src/models/RunnerOrganisation.ts +++ b/src/models/RunnerOrganisation.ts @@ -1,4 +1,4 @@ -import { Entity, Column } from "typeorm"; +import { Entity, Column, ManyToOne } from "typeorm"; import { IsOptional,} from "class-validator"; import { RunnerGroup } from "./RunnerGroup"; import { Address } from "./Address"; @@ -15,6 +15,6 @@ export class RunnerOrganisation extends RunnerGroup { */ @Column() @IsOptional() - //TODO: Relationship + @ManyToOne(() => Address, address => address.groups) address?: Address; } \ No newline at end of file From 0d9d72c223782310a86a20ef483d695b8845dbdd Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:51:16 +0100 Subject: [PATCH 34/53] Added relations for RunnerTeams ref #11 --- src/models/RunnerGroup.ts | 7 +++++++ src/models/RunnerTeam.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index c35ad48..652b861 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -7,6 +7,7 @@ import { } from "class-validator"; import { GroupContact } from "./GroupContact"; import { Runner } from "./Runner"; +import { RunnerTeam } from "./RunnerTeam"; /** * Defines the runnerGroup interface. @@ -42,4 +43,10 @@ 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/RunnerTeam.ts b/src/models/RunnerTeam.ts index 204bc01..1799e30 100644 --- a/src/models/RunnerTeam.ts +++ b/src/models/RunnerTeam.ts @@ -1,4 +1,4 @@ -import { Entity, Column } from "typeorm"; +import { Entity, Column, ManyToOne } from "typeorm"; import { IsNotEmpty } from "class-validator"; import { RunnerGroup } from "./RunnerGroup"; @@ -14,6 +14,6 @@ export class RunnerTeam extends RunnerGroup { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => RunnerGroup, group => group.teams) parentGroup?: RunnerGroup; } \ No newline at end of file From 8e2eac9dc07d99da7c150e393164e96fafcdc632 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:32:11 +0100 Subject: [PATCH 35/53] Added relations for Scans ref #11 --- src/models/Runner.ts | 7 +++++++ src/models/Scan.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/models/Runner.ts b/src/models/Runner.ts index 3db90fc..dc2cbe2 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -4,6 +4,7 @@ import { Participant } from "./Participant"; import { RunnerGroup } from "./RunnerGroup"; import { DistanceDonation } from "./DistanceDonation"; import { RunnerCard } from "./RunnerCard"; +import { Scan } from "./Scan"; /** * Defines a runner. @@ -29,4 +30,10 @@ export class Runner extends Participant { */ @OneToMany(() => RunnerCard, card => card.runner) cards: RunnerCard[]; + + /** + * Used to link runners to a scans + */ + @OneToMany(() => Scan, scan => scan.runner) + scans: Scan[]; } diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 3991b7a..51d71c3 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, @@ -24,7 +24,7 @@ export abstract class Scan { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => Runner, runner => runner.scans) runner: Runner; /** From f32291d7142ed262680e627832594984b901c7e4 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:34:04 +0100 Subject: [PATCH 36/53] Added scan station relationship ref #11 --- src/models/ScanStation.ts | 4 ++-- src/models/Track.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/ScanStation.ts b/src/models/ScanStation.ts index 2989be0..cd317af 100644 --- a/src/models/ScanStation.ts +++ b/src/models/ScanStation.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { IsBoolean, IsInt, @@ -34,7 +34,7 @@ export class ScanStation { */ @Column() @IsNotEmpty() - //TODO: Relation + @ManyToOne(() => Track, track => track.stations) track: Track; /** diff --git a/src/models/Track.ts b/src/models/Track.ts index d5aeaa5..e8689a4 100644 --- a/src/models/Track.ts +++ b/src/models/Track.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; import { IsInt, IsNotEmpty, @@ -6,6 +6,7 @@ import { IsPositive, IsString, } from "class-validator"; +import { ScanStation } from "./ScanStation"; /** * Defines a track of given length. @@ -35,4 +36,10 @@ export class Track { @IsInt() @IsPositive() distance: number; + + /** + * Used to link scan stations to track. + */ + @OneToMany(() => ScanStation, station => station.track) + stations: ScanStation[]; } From 4d593eb840f51d33746479a26787c30f5a3983f5 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:36:11 +0100 Subject: [PATCH 37/53] Removed relation that was already implemented in the super ref #11 --- src/models/TrackScan.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts index c7bc0b9..f6ffb81 100644 --- a/src/models/TrackScan.ts +++ b/src/models/TrackScan.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { IsBoolean, IsDateString, @@ -25,14 +25,6 @@ export class TrackScan extends Scan { @IsInt() id: number; - /** - * The associated runner. - */ - @Column() - @IsNotEmpty() - //TODO: Relationship - runner: Runner; - /** * The associated track. */ From c1242b2a2aa0cc2bb07caf845a204052ac3934a7 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:40:25 +0100 Subject: [PATCH 38/53] Added TrackScan relationships ref #11 --- src/models/RunnerCard.ts | 9 ++++++++- src/models/ScanStation.ts | 9 ++++++++- src/models/Track.ts | 7 +++++++ src/models/TrackScan.ts | 6 +++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/models/RunnerCard.ts b/src/models/RunnerCard.ts index 151f58c..b5a3e5a 100644 --- a/src/models/RunnerCard.ts +++ b/src/models/RunnerCard.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm"; import { IsBoolean, IsInt, @@ -7,6 +7,7 @@ import { IsString, } from "class-validator"; import { Runner } from "./Runner"; +import { TrackScan } from "./TrackScan"; /** * Defines a card that can be scanned via a scanner station. @@ -46,4 +47,10 @@ export class RunnerCard { @Column() @IsBoolean() enabled = true; + + /** + * Used to link cards to a track scans. + */ + @OneToMany(() => TrackScan, scan => scan.track) + scans: TrackScan[]; } diff --git a/src/models/ScanStation.ts b/src/models/ScanStation.ts index cd317af..5950ad0 100644 --- a/src/models/ScanStation.ts +++ b/src/models/ScanStation.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm"; import { IsBoolean, IsInt, @@ -7,6 +7,7 @@ import { IsString, } from "class-validator"; import { Track } from "./Track"; +import { TrackScan } from "./TrackScan"; /** * ScannerStations have the ability to create scans for specific tracks. @@ -51,4 +52,10 @@ export class ScanStation { @Column() @IsBoolean() enabled = true; + + /** + * Used to link track scans to a scan station. + */ + @OneToMany(() => TrackScan, scan => scan.track) + scans: TrackScan[]; } diff --git a/src/models/Track.ts b/src/models/Track.ts index e8689a4..eda6def 100644 --- a/src/models/Track.ts +++ b/src/models/Track.ts @@ -7,6 +7,7 @@ import { IsString, } from "class-validator"; import { ScanStation } from "./ScanStation"; +import { TrackScan } from "./TrackScan"; /** * Defines a track of given length. @@ -42,4 +43,10 @@ export class Track { */ @OneToMany(() => ScanStation, station => station.track) stations: ScanStation[]; + + /** + * Used to link track scans to a track. + */ + @OneToMany(() => TrackScan, scan => scan.track) + scans: TrackScan[]; } diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts index f6ffb81..5eeb1bf 100644 --- a/src/models/TrackScan.ts +++ b/src/models/TrackScan.ts @@ -30,7 +30,7 @@ export class TrackScan extends Scan { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => Track, track => track.scans) track: Track; /** @@ -38,7 +38,7 @@ export class TrackScan extends Scan { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => RunnerCard, card => card.scans) card: RunnerCard; /** @@ -46,7 +46,7 @@ export class TrackScan extends Scan { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => ScanStation, station => station.scans) station: ScanStation; /** From c82cc9a67060268518b33b4e6ee383292c529998 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:44:56 +0100 Subject: [PATCH 39/53] Moved attribute to super ref #11 --- src/models/Scan.ts | 7 +++++++ src/models/TrackScan.ts | 15 --------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 51d71c3..8fb7215 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -33,4 +33,11 @@ export abstract class Scan { @IsInt() @IsPositive() abstract distance: number; + + /** + * Is the scan valid (for fraud reasons). + */ + @Column() + @Boolean() + valid = true; } diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts index 5eeb1bf..3691cf1 100644 --- a/src/models/TrackScan.ts +++ b/src/models/TrackScan.ts @@ -17,14 +17,6 @@ import { ScanStation } from "./ScanStation"; * Defines the scan interface. */ export class TrackScan extends Scan { - /** - * Autogenerated unique id (primary key). - */ - @PrimaryGeneratedColumn() - @IsOptional() - @IsInt() - id: number; - /** * The associated track. */ @@ -65,11 +57,4 @@ export class TrackScan extends Scan { @IsDateString() @IsNotEmpty() timestamp: string; - - /** - * Is the scan valid (for fraud reasons). - */ - @Column() - @IsBoolean() - valid = true; } From abf7aaeda3a39aecac98756c19b275405d869cb5 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:46:43 +0100 Subject: [PATCH 40/53] Fixed import ref #11 --- src/models/Scan.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 8fb7215..38c18c9 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -1,5 +1,6 @@ import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { + IsBoolean, IsInt, IsNotEmpty, IsOptional, @@ -38,6 +39,6 @@ export abstract class Scan { * Is the scan valid (for fraud reasons). */ @Column() - @Boolean() + @IsBoolean() valid = true; } From 84dd1fe4a5871e1bf3d5510bb92d826d519dd6ad Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:46:53 +0100 Subject: [PATCH 41/53] Added missing getter --- src/models/Runner.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/models/Runner.ts b/src/models/Runner.ts index dc2cbe2..bb0047a 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -1,5 +1,5 @@ import { Entity, Column, OneToMany, ManyToOne } from "typeorm"; -import { IsNotEmpty,} from "class-validator"; +import { IsInt, IsNotEmpty,} from "class-validator"; import { Participant } from "./Participant"; import { RunnerGroup } from "./RunnerGroup"; import { DistanceDonation } from "./DistanceDonation"; @@ -36,4 +36,10 @@ export class Runner extends Participant { */ @OneToMany(() => Scan, scan => scan.runner) scans: Scan[]; + + @IsInt() + public get distance() : number { + return this.scans.filter(scan => scan.valid === true).reduce((sum, current) => sum + current.distance, 0); + } + } From d0a1ea3292cf7c033d24a39ba6fdccde3c0f4022 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 15:49:19 +0100 Subject: [PATCH 42/53] Renamed getter ref #11 --- src/models/DistanceDonation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/DistanceDonation.ts b/src/models/DistanceDonation.ts index 915362b..55236d1 100644 --- a/src/models/DistanceDonation.ts +++ b/src/models/DistanceDonation.ts @@ -33,7 +33,7 @@ export class DistanceDonation extends Donation { public get amount(): number { let calculatedAmount = -1; try { - calculatedAmount = this.amountPerDistance * this.runner.getDistance(); + calculatedAmount = this.amountPerDistance * this.runner.distance; } catch (error) { throw error; } From dd5f4488be9cf5df6fae740f60fb5597382ca984 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 16:00:09 +0100 Subject: [PATCH 43/53] Cleaned up relations ref #11 --- src/models/DistanceDonation.ts | 1 - src/models/Donation.ts | 1 - src/models/Participant.ts | 1 - src/models/Runner.ts | 1 - src/models/RunnerCard.ts | 1 - src/models/RunnerGroup.ts | 1 - src/models/RunnerOrganisation.ts | 1 - src/models/RunnerTeam.ts | 1 - src/models/Scan.ts | 1 - src/models/ScanStation.ts | 1 - src/models/TrackScan.ts | 3 --- 11 files changed, 13 deletions(-) diff --git a/src/models/DistanceDonation.ts b/src/models/DistanceDonation.ts index 55236d1..878f8cb 100644 --- a/src/models/DistanceDonation.ts +++ b/src/models/DistanceDonation.ts @@ -12,7 +12,6 @@ export class DistanceDonation extends Donation { /** * The runner associated. */ - @Column() @IsNotEmpty() @ManyToOne(() => Runner, runner => runner.distanceDonations) runner: Runner; diff --git a/src/models/Donation.ts b/src/models/Donation.ts index f7ea19c..3d59202 100644 --- a/src/models/Donation.ts +++ b/src/models/Donation.ts @@ -22,7 +22,6 @@ export abstract class Donation { /** * The donations's donor. */ - @Column() @IsNotEmpty() @ManyToOne(() => Participant, donor => donor.donations) donor: Participant; diff --git a/src/models/Participant.ts b/src/models/Participant.ts index e70e14e..0465e01 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -51,7 +51,6 @@ export abstract class Participant { * The participant's address. * Optional */ - @Column() @IsOptional() @ManyToOne(() => Address, address => address.participants) address?: Address; diff --git a/src/models/Runner.ts b/src/models/Runner.ts index bb0047a..3a8532a 100644 --- a/src/models/Runner.ts +++ b/src/models/Runner.ts @@ -14,7 +14,6 @@ export class Runner extends Participant { /** * The runner's associated group. */ - @Column() @IsNotEmpty() @ManyToOne(() => RunnerGroup, group => group.runners) group: RunnerGroup; diff --git a/src/models/RunnerCard.ts b/src/models/RunnerCard.ts index b5a3e5a..e751506 100644 --- a/src/models/RunnerCard.ts +++ b/src/models/RunnerCard.ts @@ -25,7 +25,6 @@ export class RunnerCard { /** * The runner that is currently associated with this card. */ - @Column() @IsOptional() @ManyToOne(() => Runner, runner => runner.cards) runner: Runner; diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index 652b861..8f4c5ea 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -33,7 +33,6 @@ export abstract class RunnerGroup { * The group's contact. * Optional */ - @Column() @IsOptional() @ManyToOne(() => GroupContact, contact => contact.groups) contact?: GroupContact; diff --git a/src/models/RunnerOrganisation.ts b/src/models/RunnerOrganisation.ts index d3e4ea8..22fe8a5 100644 --- a/src/models/RunnerOrganisation.ts +++ b/src/models/RunnerOrganisation.ts @@ -13,7 +13,6 @@ export class RunnerOrganisation extends RunnerGroup { * The organisations's address. * Optional */ - @Column() @IsOptional() @ManyToOne(() => Address, address => address.groups) address?: Address; diff --git a/src/models/RunnerTeam.ts b/src/models/RunnerTeam.ts index 1799e30..e716e27 100644 --- a/src/models/RunnerTeam.ts +++ b/src/models/RunnerTeam.ts @@ -12,7 +12,6 @@ export class RunnerTeam extends RunnerGroup { * The team's parent group. * Optional */ - @Column() @IsNotEmpty() @ManyToOne(() => RunnerGroup, group => group.teams) parentGroup?: RunnerGroup; diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 38c18c9..6e3f654 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -23,7 +23,6 @@ export abstract class Scan { /** * The associated runner. */ - @Column() @IsNotEmpty() @ManyToOne(() => Runner, runner => runner.scans) runner: Runner; diff --git a/src/models/ScanStation.ts b/src/models/ScanStation.ts index 5950ad0..c89a3a4 100644 --- a/src/models/ScanStation.ts +++ b/src/models/ScanStation.ts @@ -33,7 +33,6 @@ export class ScanStation { /** * The track this station is associated with. */ - @Column() @IsNotEmpty() @ManyToOne(() => Track, track => track.stations) track: Track; diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts index 3691cf1..0f08d2a 100644 --- a/src/models/TrackScan.ts +++ b/src/models/TrackScan.ts @@ -20,7 +20,6 @@ export class TrackScan extends Scan { /** * The associated track. */ - @Column() @IsNotEmpty() @ManyToOne(() => Track, track => track.scans) track: Track; @@ -28,7 +27,6 @@ export class TrackScan extends Scan { /** * The associated card. */ - @Column() @IsNotEmpty() @ManyToOne(() => RunnerCard, card => card.scans) card: RunnerCard; @@ -36,7 +34,6 @@ export class TrackScan extends Scan { /** * The scanning station. */ - @Column() @IsNotEmpty() @ManyToOne(() => ScanStation, station => station.scans) station: ScanStation; From 5bf978d32dc8e9d49d9fcff0adeb75c8ee50ad03 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 16:07:18 +0100 Subject: [PATCH 44/53] Turned the abstracts into entities ref #11 --- src/models/Donation.ts | 3 ++- src/models/Participant.ts | 3 ++- src/models/RunnerGroup.ts | 3 ++- src/models/Scan.ts | 3 ++- src/models/TrackScan.ts | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/models/Donation.ts b/src/models/Donation.ts index 3d59202..7143c99 100644 --- a/src/models/Donation.ts +++ b/src/models/Donation.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm"; import { IsInt, IsNotEmpty, @@ -10,6 +10,7 @@ import { Participant } from "./Participant"; /** * Defines the donation interface. */ +@Entity() export abstract class Donation { /** * Autogenerated unique id (primary key). diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 0465e01..2f4327b 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm"; import { IsEmail, IsInt, @@ -13,6 +13,7 @@ import { Donation } from "./Donation"; /** * Defines the participant interface. */ +@Entity() export abstract class Participant { /** * Autogenerated unique id (primary key). diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index 8f4c5ea..52f478f 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm"; import { IsInt, IsNotEmpty, @@ -12,6 +12,7 @@ import { RunnerTeam } from "./RunnerTeam"; /** * Defines the runnerGroup interface. */ +@Entity() export abstract class RunnerGroup { /** * Autogenerated unique id (primary key). diff --git a/src/models/Scan.ts b/src/models/Scan.ts index 6e3f654..6c2dccc 100644 --- a/src/models/Scan.ts +++ b/src/models/Scan.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm"; import { IsBoolean, IsInt, @@ -11,6 +11,7 @@ import { Runner } from "./Runner"; /** * Defines the scan interface. */ +@Entity() export abstract class Scan { /** * Autogenerated unique id (primary key). diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts index 0f08d2a..ce35ee8 100644 --- a/src/models/TrackScan.ts +++ b/src/models/TrackScan.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm"; import { IsBoolean, IsDateString, @@ -16,6 +16,7 @@ import { ScanStation } from "./ScanStation"; /** * Defines the scan interface. */ +@Entity() export class TrackScan extends Scan { /** * The associated track. From ac0ce799f950dac194192177329d07c802feb457 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 17:40:03 +0100 Subject: [PATCH 45/53] 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 46/53] 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. From 48e28e7b7a19e1ad66ba12461826676bd9074a58 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:07:33 +0100 Subject: [PATCH 47/53] User + UserGroup --- src/models/User.ts | 100 ++++++++++++++++++++++++++++++++++++++++ src/models/UserGroup.ts | 44 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/models/User.ts create mode 100644 src/models/UserGroup.ts diff --git a/src/models/User.ts b/src/models/User.ts new file mode 100644 index 0000000..e575a79 --- /dev/null +++ b/src/models/User.ts @@ -0,0 +1,100 @@ +import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique } from "typeorm"; +import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator"; +import { UserGroup } from './UserGroup'; + +/** + * Defines a admin user. +*/ +@Entity() +export class User { + /** + * autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * autogenerated uuid + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + @Generated("uuid") + uuid: string; + + /** + * user email + */ + @IsEmail() + email: string; + + /** + * username + */ + @IsString() + username: string; + + /** + * firstname + */ + @IsString() + @IsNotEmpty() + firstname: string; + + /** + * middlename + */ + @IsString() + @IsOptional() + middlename: string; + + /** + * lastname + */ + @IsString() + @IsNotEmpty() + lastname: string; + + /** + * password + */ + @IsString() + @IsNotEmpty() + password: string; + + /** + * userpermissions + */ + // TODO: UserPermission implementation + // @OneToMany(() => UserPermission,userpermission=>) + // userpermissions: UserPermission[]; + + /** + * groups + */ + // TODO: UserGroup implementation + // @OneToMany(() => UserGroup, usergroup => usergroup.) + @IsOptional() + groups: UserGroup[]; + + /** + * is user enabled? + */ + @IsBoolean() + enabled: boolean; + + /** + * jwt refresh count + */ + @IsInt() + @Column({ default: 1 }) + refreshTokenCount: number; + + /** + * profilepic + */ + @IsString() + profilepic: string; +} diff --git a/src/models/UserGroup.ts b/src/models/UserGroup.ts new file mode 100644 index 0000000..61a434e --- /dev/null +++ b/src/models/UserGroup.ts @@ -0,0 +1,44 @@ +import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; +import { User } from "./User"; + +/** + * Defines the UserGroup interface. +*/ +@Entity() +export abstract class UserGroup { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The group's name + */ + @Column() + @IsNotEmpty() + @IsString() + name: string; + + /** + * The group's description + */ + @Column() + @IsOptional() + @IsString() + description: string; + + /** + * Used to link users to a user group. + */ + // TODO: + // grouppermissions: GroupPermissions[]; +} \ No newline at end of file From d47983a032c5bb4d4b2958cc013df0b92ece2844 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:11:23 +0100 Subject: [PATCH 48/53] =?UTF-8?q?=F0=9F=9A=A7=20User=20class=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/User.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/models/User.ts b/src/models/User.ts index e575a79..fcc897e 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -18,7 +18,6 @@ export class User { /** * autogenerated uuid */ - @PrimaryGeneratedColumn() @IsOptional() @IsInt() @Generated("uuid") From 4a9fd57356132b2fce539724c2faecdc6f160e7f Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 2 Dec 2020 18:20:53 +0100 Subject: [PATCH 49/53] Fixed user<-> Group relationship --- src/models/User.ts | 7 +++---- src/models/UserGroup.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/models/User.ts b/src/models/User.ts index fcc897e..e068b57 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique } from "typeorm"; +import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm"; import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator"; import { UserGroup } from './UserGroup'; @@ -73,9 +73,8 @@ export class User { /** * groups */ - // TODO: UserGroup implementation - // @OneToMany(() => UserGroup, usergroup => usergroup.) - @IsOptional() + @ManyToMany(() => UserGroup) + @JoinTable() groups: UserGroup[]; /** diff --git a/src/models/UserGroup.ts b/src/models/UserGroup.ts index 61a434e..96b1633 100644 --- a/src/models/UserGroup.ts +++ b/src/models/UserGroup.ts @@ -37,7 +37,7 @@ export abstract class UserGroup { description: string; /** - * Used to link users to a user group. + * TODO: Something about permission stuff */ // TODO: // grouppermissions: GroupPermissions[]; From 82ca8f48dc8cd5438ba1eeab7b222b1df60355df Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:27:00 +0100 Subject: [PATCH 50/53] =?UTF-8?q?=F0=9F=9A=A7=20UserAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/UserAction.ts | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/models/UserAction.ts diff --git a/src/models/UserAction.ts b/src/models/UserAction.ts new file mode 100644 index 0000000..7f6dc43 --- /dev/null +++ b/src/models/UserAction.ts @@ -0,0 +1,48 @@ +import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; + +/** + * Defines the UserAction interface. +*/ +@Entity() +export class UserAction { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + // TODO: + // user: relation + + /** + * The actions's target (e.g. Track#2) + */ + @Column() + @IsNotEmpty() + @IsString() + target: string; + + /** + * The actions's action (e.g. UPDATE) + */ + @Column() + @IsNotEmpty() + @IsString() + action: string; + + /** + * The description of change (before-> after; e.g. distance:15->17) + */ + @Column() + @IsOptional() + @IsString() + changed: string; +} \ No newline at end of file From 1d5726492286f21adcc6064c62159de8d134538d Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:27:06 +0100 Subject: [PATCH 51/53] =?UTF-8?q?=F0=9F=9A=A7=20Permissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/Permission.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/models/Permission.ts diff --git a/src/models/Permission.ts b/src/models/Permission.ts new file mode 100644 index 0000000..4dfeff2 --- /dev/null +++ b/src/models/Permission.ts @@ -0,0 +1,37 @@ +import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; + +/** + * Defines the UserGroup interface. +*/ +@Entity() +export abstract class UserGroup { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The target + */ + @Column() + @IsNotEmpty() + @IsString() + target: string; + + /** + * The action type + */ + @Column() + @IsNotEmpty() + @IsString() + action: string; +} \ No newline at end of file From e4d5afbebe7179c926a0625fd11d17f5285e55a8 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:28:48 +0100 Subject: [PATCH 52/53] =?UTF-8?q?=F0=9F=9A=A7=20Permission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/Permission.ts | 4 ++-- src/models/User.ts | 9 +++++---- src/models/UserGroup.ts | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/models/Permission.ts b/src/models/Permission.ts index 4dfeff2..e5d3d3c 100644 --- a/src/models/Permission.ts +++ b/src/models/Permission.ts @@ -7,10 +7,10 @@ import { } from "class-validator"; /** - * Defines the UserGroup interface. + * Defines the Permission interface. */ @Entity() -export abstract class UserGroup { +export abstract class Permission { /** * Autogenerated unique id (primary key). */ diff --git a/src/models/User.ts b/src/models/User.ts index e068b57..b59ad3f 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -1,6 +1,7 @@ import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm"; import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator"; import { UserGroup } from './UserGroup'; +import { Permission } from './Permission'; /** * Defines a admin user. @@ -64,11 +65,11 @@ export class User { password: string; /** - * userpermissions + * permissions */ - // TODO: UserPermission implementation - // @OneToMany(() => UserPermission,userpermission=>) - // userpermissions: UserPermission[]; + // TODO: Permission implementation + // @OneToMany(() => Permission,userpermission=>) + // permissions: Permission[]; /** * groups diff --git a/src/models/UserGroup.ts b/src/models/UserGroup.ts index 96b1633..90f6378 100644 --- a/src/models/UserGroup.ts +++ b/src/models/UserGroup.ts @@ -5,7 +5,7 @@ import { IsOptional, IsString, } from "class-validator"; -import { User } from "./User"; +import { Permission } from "./Permission"; /** * Defines the UserGroup interface. @@ -40,5 +40,5 @@ export abstract class UserGroup { * TODO: Something about permission stuff */ // TODO: - // grouppermissions: GroupPermissions[]; + // grouppermissions: Permission[]; } \ No newline at end of file From a78bbb1de5765f6339440663bb884367b6d3bfdf Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:46:36 +0100 Subject: [PATCH 53/53] =?UTF-8?q?=F0=9F=9A=A7=20User=20+=20Permissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/Permission.ts | 17 +++++++++++++++-- src/models/User.ts | 16 +++++++++++++--- src/models/UserGroup.ts | 14 +++++++------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/models/Permission.ts b/src/models/Permission.ts index e5d3d3c..e9b049b 100644 --- a/src/models/Permission.ts +++ b/src/models/Permission.ts @@ -1,11 +1,12 @@ -import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, IsOptional, IsString, } from "class-validator"; - +import { User } from './User'; +import { UserGroup } from './UserGroup'; /** * Defines the Permission interface. */ @@ -19,6 +20,18 @@ export abstract class Permission { @IsInt() id: number; + /** + * users + */ + @OneToMany(() => User, user => user.permissions) + users: User[] + + /** + * groups + */ + @OneToMany(() => UserGroup, group => group.permissions) + groups: UserGroup[] + /** * The target */ diff --git a/src/models/User.ts b/src/models/User.ts index b59ad3f..d946500 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -67,9 +67,8 @@ export class User { /** * permissions */ - // TODO: Permission implementation - // @OneToMany(() => Permission,userpermission=>) - // permissions: Permission[]; + @ManyToOne(() => Permission, permission => permission.users) + permissions: Permission[]; /** * groups @@ -96,4 +95,15 @@ export class User { */ @IsString() profilepic: string; + + /** + * calculate all permissions + */ + public get calc_permissions(): Permission[] { + let final_permissions = this.groups.forEach((permission) => { + console.log(permission); + }) + // TODO: add user permissions on top of group permissions + return + return [] + } } diff --git a/src/models/UserGroup.ts b/src/models/UserGroup.ts index 90f6378..5a19713 100644 --- a/src/models/UserGroup.ts +++ b/src/models/UserGroup.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, @@ -20,6 +20,12 @@ export abstract class UserGroup { @IsInt() id: number; + /** + * permissions + */ + @ManyToOne(() => Permission, permission => permission.groups) + permissions: Permission[]; + /** * The group's name */ @@ -35,10 +41,4 @@ export abstract class UserGroup { @IsOptional() @IsString() description: string; - - /** - * TODO: Something about permission stuff - */ - // TODO: - // grouppermissions: Permission[]; } \ No newline at end of file