backend/src/models/responses/ResponseSelfServiceDonation.ts

43 lines
1.4 KiB
TypeScript

import { IsInt, IsNotEmpty, IsPositive } from 'class-validator';
import { DistanceDonation } from '../entities/DistanceDonation';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseSelfServiceDonor } from './ResponseSelfServiceDonor';
/**
* Defines the runner selfservice donation response.
* Why? B/C runner's are not allowed to view all information available to admin users.
*/
export class ResponseSelfServiceDonation implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.SELFSERVICEDONATION;
/**
* The donation's donor.
*/
@IsNotEmpty()
donor: ResponseSelfServiceDonor;
/**
* The donation's amount in the smalles unit of your currency (default: euro cent).
*/
@IsInt()
amount: number;
/**
* 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;
public constructor(donation: DistanceDonation) {
this.donor = new ResponseSelfServiceDonor(donation.donor);
this.amountPerDistance = donation.amountPerDistance;
this.amount = donation.amount;
}
}