backend/src/models/responses/ResponseStatsTeam.ts
Nicolai Ort 377d5dadb2
All checks were successful
continuous-integration/drone/pr Build is passing
Potential fix for all remaining errors
ref #190
2021-04-07 16:38:20 +02:00

72 lines
1.7 KiB
TypeScript

import {
IsInt,
IsObject,
IsString
} from "class-validator";
import { RunnerTeam } from '../entities/RunnerTeam';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseRunnerGroup } from './ResponseRunnerGroup';
/**
* Defines the team stats response.
* This differs from the normal team responce.
*/
export class ResponseStatsTeam implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.STATSTEAM;
/**
* The team's id.
*/
@IsInt()
id: number;
/**
* The team's name.
*/
@IsString()
name: string;
/**
* The teams's currently ran distance in meters.
*/
@IsInt()
distance: number;
/**
* The teams's currently collected donations.
*/
@IsInt()
donationAmount: number;
/**
* The teams's parent group.
*/
@IsObject()
parent: ResponseRunnerGroup;
/**
* Creates a new team stats response from a team
* @param team The team whoes response shall be generated - the following relations have to be resolved: runners, runners.scans, runners.distanceDonations, runners.scans.track
*/
public constructor(team: RunnerTeam) {
this.name = team.name;
this.id = team.id;
this.parent = team.parentGroup.toResponse();
try {
this.distance = team.distance;
} catch {
this.distance = -1;
}
try {
this.donationAmount = team.distanceDonationAmount;
} catch {
this.donationAmount = -1;
}
}
}