44
									
								
								src/models/actions/update/UpdateDonor.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/models/actions/update/UpdateDonor.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
 | 
			
		||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
 | 
			
		||||
import { Donor } from '../../entities/Donor';
 | 
			
		||||
import { CreateParticipant } from './CreateParticipant';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class is used to update a Donor entity (via put request).
 | 
			
		||||
 */
 | 
			
		||||
export class UpdateDonor extends CreateParticipant {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The updated donor's id.
 | 
			
		||||
     * This shouldn't have changed but it is here in case anyone ever wants to enable id changes (whyever they would want to).
 | 
			
		||||
     */
 | 
			
		||||
    @IsInt()
 | 
			
		||||
    id: number;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Does the updated donor need a receipt?
 | 
			
		||||
     */
 | 
			
		||||
    @IsBoolean()
 | 
			
		||||
    @IsOptional()
 | 
			
		||||
    receiptNeeded?: boolean;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Updates a provided Donor entity based on this.
 | 
			
		||||
     */
 | 
			
		||||
    public async updateDonor(donor: Donor): Promise<Donor> {
 | 
			
		||||
        donor.firstname = this.firstname;
 | 
			
		||||
        donor.middlename = this.middlename;
 | 
			
		||||
        donor.lastname = this.lastname;
 | 
			
		||||
        donor.phone = this.phone;
 | 
			
		||||
        donor.email = this.email;
 | 
			
		||||
        donor.receiptNeeded = this.receiptNeeded;
 | 
			
		||||
        donor.address = await this.getAddress();
 | 
			
		||||
 | 
			
		||||
        if (this.receiptNeeded == true && this.address == null) {
 | 
			
		||||
            throw new DonorReceiptAddressNeededError()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return donor;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user