54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { IsInt, IsNotEmpty, IsNumber, IsObject, IsOptional, IsString } from "class-validator";
|
|
import { RunnerGroup } from '../entities/RunnerGroup';
|
|
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
|
import { IResponse } from './IResponse';
|
|
import { ResponseGroupContact } from './ResponseGroupContact';
|
|
|
|
/**
|
|
* Defines the runnerGroup response.
|
|
*/
|
|
export abstract class ResponseRunnerGroup implements IResponse {
|
|
/**
|
|
* The responseType.
|
|
* This contains the type of class/entity this response contains.
|
|
*/
|
|
responseType: ResponseObjectType = ResponseObjectType.RUNNERGROUP;
|
|
|
|
/**
|
|
* The runnerGroup's id.
|
|
*/
|
|
@IsInt()
|
|
@IsNotEmpty()
|
|
id: number;;
|
|
|
|
/**
|
|
* The runnerGroup's name.
|
|
*/
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
name: string;
|
|
|
|
|
|
/**
|
|
* The runnerGroup's contact.
|
|
*/
|
|
@IsObject()
|
|
@IsOptional()
|
|
contact?: ResponseGroupContact;
|
|
|
|
@IsOptional()
|
|
@IsNumber()
|
|
total_distance: number
|
|
|
|
/**
|
|
* Creates a ResponseRunnerGroup object from a runnerGroup.
|
|
* @param group The runnerGroup the response shall be build for.
|
|
*/
|
|
public constructor(group: RunnerGroup) {
|
|
this.id = group.id;
|
|
this.name = group.name;
|
|
if (group.contact) { this.contact = group.contact.toResponse(); };
|
|
if (group.runners) { this.total_distance = group.runners.reduce((p, c) => p + c.distance, 0) }
|
|
}
|
|
}
|