Added everything for basic donor creation

ref #65
This commit is contained in:
2021-01-02 16:51:33 +01:00
parent a83fedc9b8
commit 557608e318
2 changed files with 39 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
import { IsBoolean, IsOptional } from 'class-validator';
import { Donor } from '../entities/Donor';
import { CreateParticipant } from './CreateParticipant';
/**
* This classed is used to create a new Donor entity from a json body (post request).
*/
export class CreateDonor extends CreateParticipant {
/**
* Does this donor need a receipt?
*/
@IsBoolean()
@IsOptional()
receiptNeeded: boolean = false;
/**
* Creates a new Donor entity from this.
*/
public async toDonor(): Promise<Donor> {
let newDonor: Donor = new Donor();
newDonor.firstname = this.firstname;
newDonor.middlename = this.middlename;
newDonor.lastname = this.lastname;
newDonor.phone = this.phone;
newDonor.email = this.email;
newDonor.receiptNeeded = this.receiptNeeded;
newDonor.address = await this.getAddress();
return newDonor;
}
}