@@ -1,5 +1,6 @@
 | 
			
		||||
import { IsBoolean, IsOptional } from 'class-validator';
 | 
			
		||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
 | 
			
		||||
import { Address } from '../../entities/Address';
 | 
			
		||||
import { Donor } from '../../entities/Donor';
 | 
			
		||||
import { CreateParticipant } from './CreateParticipant';
 | 
			
		||||
 | 
			
		||||
@@ -29,7 +30,7 @@ export class CreateDonor extends CreateParticipant {
 | 
			
		||||
        newDonor.receiptNeeded = this.receiptNeeded;
 | 
			
		||||
        newDonor.address = this.address;
 | 
			
		||||
 | 
			
		||||
        if (this.receiptNeeded == true && this.address.isValidAddress == false) {
 | 
			
		||||
        if (this.receiptNeeded == true && Address.isValidAddress(newDonor.address) == false) {
 | 
			
		||||
            throw new DonorReceiptAddressNeededError()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
 | 
			
		||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
 | 
			
		||||
import { Address } from '../../entities/Address';
 | 
			
		||||
import { Donor } from '../../entities/Donor';
 | 
			
		||||
import { CreateParticipant } from '../create/CreateParticipant';
 | 
			
		||||
 | 
			
		||||
@@ -34,8 +35,7 @@ export class UpdateDonor extends CreateParticipant {
 | 
			
		||||
        donor.email = this.email;
 | 
			
		||||
        donor.receiptNeeded = this.receiptNeeded;
 | 
			
		||||
        donor.address = this.address;
 | 
			
		||||
 | 
			
		||||
        if (this.receiptNeeded == true && this.address == null) {
 | 
			
		||||
        if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) {
 | 
			
		||||
            throw new DonorReceiptAddressNeededError()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -59,8 +59,9 @@ export class Address {
 | 
			
		||||
  /**
 | 
			
		||||
   * Checks if this is a valid address
 | 
			
		||||
   */
 | 
			
		||||
  public get isValidAddress(): Boolean {
 | 
			
		||||
    if (!this.address1 || !this.city || !this.country || !this.postalcode) { return false; }
 | 
			
		||||
  public static isValidAddress(address: Address): Boolean {
 | 
			
		||||
    if (address == null) { return false; }
 | 
			
		||||
    if (address.address1 == null || address.city == null || address.country == null || address.postalcode == null) { return false; }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user