import { IsInt, IsObject } from "class-validator"; import { Runner } from '../entities/Runner'; import { ResponseObjectType } from '../enums/ResponseObjectType'; import { IResponse } from './IResponse'; import { ResponseParticipant } from './ResponseParticipant'; import { ResponseRunnerGroup } from './ResponseRunnerGroup'; /** * Defines the runner response. */ export class ResponseRunner extends ResponseParticipant implements IResponse { /** * The responseType. * This contains the type of class/entity this response contains. */ responseType: ResponseObjectType = ResponseObjectType.RUNNER; /** * The runner's currently ran distance in meters. */ @IsInt() distance: number; /** * The runner's group. */ @IsObject() group: ResponseRunnerGroup; /** * Creates a ResponseRunner object from a runner. * @param runner The user the response shall be build for. */ public constructor(runner: Runner) { super(runner); if (!runner.scans) { this.distance = 0 } else { this.distance = runner.validScans.reduce((sum, current) => sum + current.distance, 0); } if (runner.group) { this.group = runner.group.toResponse(); } } }