backend/src/models/entities/Donation.ts

35 lines
848 B
TypeScript

import {
IsInt,
IsNotEmpty,
IsOptional
} from "class-validator";
import { Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Participant } from "./Participant";
/**
* Defines the donation interface.
*/
@Entity()
@TableInheritance({ column: { name: "type", type: "varchar" } })
export abstract class Donation {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The donations's donor.
*/
@IsNotEmpty()
@ManyToOne(() => Participant, donor => donor.donations, { nullable: true })
donor: Participant;
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
* The exact implementation may differ for each type of donation.
*/
abstract amount: number | Promise<number>;
}