38
src/models/actions/create/CreateDonor.ts
Normal file
38
src/models/actions/create/CreateDonor.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { IsBoolean, IsOptional } from 'class-validator';
|
||||
import { DonorReceiptAddressNeededError } from '../../errors/DonorErrors';
|
||||
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.address = await this.getAddress();
|
||||
newDonor.receiptNeeded = this.receiptNeeded;
|
||||
|
||||
if (this.receiptNeeded == true && this.address == null) {
|
||||
throw new DonorReceiptAddressNeededError()
|
||||
}
|
||||
|
||||
return newDonor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user