backend/src/models/responses/ResponseDistanceDonation.ts
Nicolai Ort ff7406e71a
All checks were successful
continuous-integration/drone/pr Build is passing
Cleaned up realations regarding response classes
ref #132
2021-01-30 16:19:42 +01:00

43 lines
1.4 KiB
TypeScript

import { IsInt, IsObject, IsPositive } from 'class-validator';
import { DistanceDonation } from '../entities/DistanceDonation';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseDonation } from './ResponseDonation';
import { ResponseRunner } from './ResponseRunner';
/**
* Defines the distance donation response.
*/
export class ResponseDistanceDonation extends ResponseDonation implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.DISTANCEDONATION;
/**
* The donation's associated runner.
* Used as the source of the donation's distance.
*/
@IsObject()
runner: ResponseRunner;
/**
* The donation's amount donated per distance.
* The amount the donor set to be donated per kilometer that the runner ran.
*/
@IsInt()
@IsPositive()
amountPerDistance: number;
/**
* Creates a ResponseDistanceDonation object from a scan.
* @param donation The distance donation the response shall be build for.
*/
public constructor(donation: DistanceDonation) {
super(donation);
if (donation.runner) { this.runner = donation.runner.toResponse(); }
this.amountPerDistance = donation.amountPerDistance;
}
}