From b480912bd8c643391865da4c7f4bfeb796315d7a Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 4 Dec 2020 22:00:48 +0100 Subject: [PATCH] Now with even more inheritance and fancy stuff: RunnerResponses now get their information from participant responses ref #13 --- src/models/responses/ResponseParticipant.ts | 61 +++++++++++++++++++++ src/models/responses/ResponseRunner.ts | 56 ++----------------- 2 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 src/models/responses/ResponseParticipant.ts diff --git a/src/models/responses/ResponseParticipant.ts b/src/models/responses/ResponseParticipant.ts new file mode 100644 index 0000000..22ec2a3 --- /dev/null +++ b/src/models/responses/ResponseParticipant.ts @@ -0,0 +1,61 @@ +import { + IsInt, + + + + IsString +} from "class-validator"; +import { Participant } from '../entities/Participant'; + +/** + * Defines a participant response. +*/ +export abstract class ResponseParticipant { + /** + * Autogenerated unique id (primary key). + */ + @IsInt() + id: number;; + + /** + * The participant's first name. + */ + @IsString() + firstname: string; + + /** + * The participant's middle name. + * Optional. + */ + @IsString() + middlename?: string; + + /** + * The participant's last name. + */ + @IsString() + lastname: string; + + /** + * The participant's phone number. + * Optional. + */ + @IsString() + phone?: string; + + /** + * The participant's e-mail address. + * Optional. + */ + @IsString() + email?: string; + + public constructor(participant: Participant) { + this.id = participant.id; + this.firstname = participant.firstname; + this.middlename = participant.middlename; + this.lastname = participant.lastname; + this.phone = participant.phone; + this.email = participant.email; + } +} diff --git a/src/models/responses/ResponseRunner.ts b/src/models/responses/ResponseRunner.ts index 591c0a3..677ca93 100644 --- a/src/models/responses/ResponseRunner.ts +++ b/src/models/responses/ResponseRunner.ts @@ -1,55 +1,15 @@ import { IsInt, - - IsObject, - - IsString + IsObject } from "class-validator"; import { Runner } from '../entities/Runner'; import { RunnerGroup } from '../entities/RunnerGroup'; +import { ResponseParticipant } from './ResponseParticipant'; /** - * Defines a track of given length. + * Defines RunnerTeam's response class. */ -export class ResponseRunner { - /** - * Autogenerated unique id (primary key). - */ - @IsInt() - id: number;; - - /** - * The runner's first name. - */ - @IsString() - firstname: string; - - /** - * The runner's middle name. - * Optional. - */ - @IsString() - middlename?: string; - - /** - * The runner's last name. - */ - @IsString() - lastname: string; - - /** - * The runner's phone number. - * Optional. - */ - @IsString() - phone?: string; - - /** - * The runner's e-mail address. - * Optional. - */ - @IsString() - email?: string; +export class ResponseRunner extends ResponseParticipant { /** * The runner's currently ran distance in meters. @@ -64,14 +24,8 @@ export class ResponseRunner { @IsObject() group: RunnerGroup; - public constructor(runner: Runner) { - this.id = runner.id; - this.firstname = runner.firstname; - this.middlename = runner.middlename; - this.lastname = runner.lastname; - this.phone = runner.phone; - this.email = runner.email; + super(runner); this.distance = runner.scans.reduce((sum, current) => sum + current.distance, 0); this.group = runner.group; }