backend/src/models/entities/FixedDonation.ts

44 lines
1.1 KiB
TypeScript

import { IsInt, IsPositive } from "class-validator";
import { ChildEntity, Column } from "typeorm";
import { ResponseDonation } from '../responses/ResponseDonation';
import { Donation } from "./Donation";
/**
* Defines the FixedDonation entity.
* In the past there was no easy way to track fixed donations (eg. for creating donation receipts).
*/
@ChildEntity()
export class FixedDonation extends Donation {
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
* This is the "real" value used by fixed donations.
*/
@Column()
@IsInt()
@IsPositive()
private _amount: number;
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
*/
@IsInt()
@IsPositive()
public get amount(): number {
return this._amount;
}
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
*/
public set amount(value: number) {
this._amount = value;
}
/**
* Turns this entity into it's response class.
*/
public toResponse(): ResponseDonation {
return new ResponseDonation(this);
}
}