From 58156e0d616dab65ad3366a383426945fd207250 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 3 Jan 2021 19:09:06 +0100 Subject: [PATCH] Implemented the first route of the toResponse normalisationf for all classes ref #67 --- src/models/entities/RunnerOrganisation.ts | 8 ++++++++ src/models/entities/RunnerTeam.ts | 8 ++++++++ src/models/entities/Scan.ts | 8 ++++++++ src/models/entities/ScanStation.ts | 7 +++++++ src/models/entities/StatsClient.ts | 8 ++++++++ src/models/entities/Track.ts | 8 ++++++++ src/models/entities/TrackScan.ts | 8 ++++++++ src/models/entities/UserAction.ts | 7 +++++++ 8 files changed, 62 insertions(+) diff --git a/src/models/entities/RunnerOrganisation.ts b/src/models/entities/RunnerOrganisation.ts index f0f8c78..ebae8fd 100644 --- a/src/models/entities/RunnerOrganisation.ts +++ b/src/models/entities/RunnerOrganisation.ts @@ -1,5 +1,6 @@ import { IsInt, IsOptional } from "class-validator"; import { ChildEntity, ManyToOne, OneToMany } from "typeorm"; +import { ResponseRunnerOrganisation } from '../responses/ResponseRunnerOrganisation'; import { Address } from './Address'; import { IAddressUser } from './IAddressUser'; import { Runner } from './Runner'; @@ -54,4 +55,11 @@ export class RunnerOrganisation extends RunnerGroup implements IAddressUser { public get distanceDonationAmount(): number { return this.allRunners.reduce((sum, current) => sum + current.distanceDonationAmount, 0); } + + /** + * Turns this entity into it's response class. + */ + public toResponse(): ResponseRunnerOrganisation { + return new ResponseRunnerOrganisation(this); + } } \ No newline at end of file diff --git a/src/models/entities/RunnerTeam.ts b/src/models/entities/RunnerTeam.ts index e84ee9b..ba4884d 100644 --- a/src/models/entities/RunnerTeam.ts +++ b/src/models/entities/RunnerTeam.ts @@ -1,5 +1,6 @@ import { IsNotEmpty } from "class-validator"; import { ChildEntity, ManyToOne } from "typeorm"; +import { ResponseRunnerTeam } from '../responses/ResponseRunnerTeam'; import { RunnerGroup } from "./RunnerGroup"; import { RunnerOrganisation } from "./RunnerOrganisation"; @@ -17,4 +18,11 @@ export class RunnerTeam extends RunnerGroup { @IsNotEmpty() @ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true }) parentGroup?: RunnerOrganisation; + + /** + * Turns this entity into it's response class. + */ + public toResponse(): ResponseRunnerTeam { + return new ResponseRunnerTeam(this); + } } \ No newline at end of file diff --git a/src/models/entities/Scan.ts b/src/models/entities/Scan.ts index 1b66851..3c1cb67 100644 --- a/src/models/entities/Scan.ts +++ b/src/models/entities/Scan.ts @@ -6,6 +6,7 @@ import { IsPositive } from "class-validator"; import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; +import { ResponseScan } from '../responses/ResponseScan'; import { Runner } from "./Runner"; /** @@ -46,4 +47,11 @@ export abstract class Scan { @Column() @IsBoolean() valid: boolean = true; + + /** + * Turns this entity into it's response class. + */ + public toResponse(): ResponseScan { + return new ResponseScan(this); + } } \ No newline at end of file diff --git a/src/models/entities/ScanStation.ts b/src/models/entities/ScanStation.ts index 1df5abf..20c5f05 100644 --- a/src/models/entities/ScanStation.ts +++ b/src/models/entities/ScanStation.ts @@ -61,4 +61,11 @@ export class ScanStation { */ @OneToMany(() => TrackScan, scan => scan.track, { nullable: true }) scans: TrackScan[]; + + /** + * Turns this entity into it's response class. + */ + public toResponse() { + return new Error("NotImplemented"); + } } diff --git a/src/models/entities/StatsClient.ts b/src/models/entities/StatsClient.ts index 493a8da..eb48cbf 100644 --- a/src/models/entities/StatsClient.ts +++ b/src/models/entities/StatsClient.ts @@ -1,5 +1,6 @@ import { IsInt, IsOptional, IsString } from "class-validator"; import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; +import { ResponseStatsClient } from '../responses/ResponseStatsClient'; /** * Defines the StatsClient entity. * StatsClients can be used to access the protected parts of the stats api (top runners, donators and so on). @@ -45,4 +46,11 @@ export class StatsClient { @IsString() @IsOptional() cleartextkey?: string; + + /** + * Turns this entity into it's response class. + */ + public toResponse(): ResponseStatsClient { + return new ResponseStatsClient(this); + } } \ No newline at end of file diff --git a/src/models/entities/Track.ts b/src/models/entities/Track.ts index df18762..5e172f7 100644 --- a/src/models/entities/Track.ts +++ b/src/models/entities/Track.ts @@ -6,6 +6,7 @@ import { IsString } from "class-validator"; import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { ResponseTrack } from '../responses/ResponseTrack'; import { ScanStation } from "./ScanStation"; import { TrackScan } from "./TrackScan"; @@ -61,4 +62,11 @@ export class Track { */ @OneToMany(() => TrackScan, scan => scan.track, { nullable: true }) scans: TrackScan[]; + + /** + * Turns this entity into it's response class. + */ + public toResponse(): ResponseTrack { + return new ResponseTrack(this); + } } diff --git a/src/models/entities/TrackScan.ts b/src/models/entities/TrackScan.ts index 45be379..8c4143b 100644 --- a/src/models/entities/TrackScan.ts +++ b/src/models/entities/TrackScan.ts @@ -6,6 +6,7 @@ import { IsPositive } from "class-validator"; import { ChildEntity, Column, ManyToOne } from "typeorm"; +import { ResponseTrackScan } from '../responses/ResponseTrackScan'; import { RunnerCard } from "./RunnerCard"; import { Scan } from "./Scan"; import { ScanStation } from "./ScanStation"; @@ -59,4 +60,11 @@ export class TrackScan extends Scan { @IsDateString() @IsNotEmpty() timestamp: string; + + /** + * Turns this entity into it's response class. + */ + public toResponse(): ResponseTrackScan { + return new ResponseTrackScan(this); + } } diff --git a/src/models/entities/UserAction.ts b/src/models/entities/UserAction.ts index d22bd37..d598be0 100644 --- a/src/models/entities/UserAction.ts +++ b/src/models/entities/UserAction.ts @@ -52,4 +52,11 @@ export class UserAction { @IsOptional() @IsString() changed: string; + + /** + * Turns this entity into it's response class. + */ + public toResponse() { + return new Error("NotImplemented"); + } } \ No newline at end of file