Implemented the first route of the toResponse normalisationf for all classes

ref #67
This commit is contained in:
Nicolai Ort 2021-01-03 19:09:06 +01:00
parent a4b0dfe43e
commit 58156e0d61
8 changed files with 62 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}
}