29 lines
842 B
TypeScript
29 lines
842 B
TypeScript
import { IsInt, IsPositive } from 'class-validator';
|
|
import { FixedDonation } from '../../entities/FixedDonation';
|
|
import { CreateDonation } from './CreateDonation';
|
|
|
|
/**
|
|
* This class is used to create a new FixedDonation entity from a json body (post request).
|
|
*/
|
|
export class CreateFixedDonation extends CreateDonation {
|
|
/**
|
|
* The donation's amount.
|
|
* The unit is your currency's smallest unit (default: euro cent).
|
|
*/
|
|
@IsInt()
|
|
@IsPositive()
|
|
amount: number;
|
|
|
|
/**
|
|
* Creates a new FixedDonation entity from this.
|
|
*/
|
|
public async toEntity(): Promise<FixedDonation> {
|
|
let newDonation = new FixedDonation;
|
|
|
|
newDonation.amount = this.amount;
|
|
newDonation.paidAmount = this.paidAmount;
|
|
newDonation.donor = await this.getDonor();
|
|
|
|
return newDonation;
|
|
}
|
|
} |