parent
8dbee32eee
commit
4824547dde
@ -1,5 +1,6 @@
|
|||||||
import { IsBoolean, IsOptional } from 'class-validator';
|
import { IsBoolean, IsOptional } from 'class-validator';
|
||||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
||||||
|
import { Address } from '../../entities/Address';
|
||||||
import { Donor } from '../../entities/Donor';
|
import { Donor } from '../../entities/Donor';
|
||||||
import { CreateParticipant } from './CreateParticipant';
|
import { CreateParticipant } from './CreateParticipant';
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ export class CreateDonor extends CreateParticipant {
|
|||||||
newDonor.receiptNeeded = this.receiptNeeded;
|
newDonor.receiptNeeded = this.receiptNeeded;
|
||||||
newDonor.address = this.address;
|
newDonor.address = this.address;
|
||||||
|
|
||||||
if (this.receiptNeeded == true && this.address.isValidAddress == false) {
|
if (this.receiptNeeded == true && Address.isValidAddress(newDonor.address) == false) {
|
||||||
throw new DonorReceiptAddressNeededError()
|
throw new DonorReceiptAddressNeededError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
|
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
|
||||||
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
import { DonorReceiptAddressNeededError } from '../../../errors/DonorErrors';
|
||||||
|
import { Address } from '../../entities/Address';
|
||||||
import { Donor } from '../../entities/Donor';
|
import { Donor } from '../../entities/Donor';
|
||||||
import { CreateParticipant } from '../create/CreateParticipant';
|
import { CreateParticipant } from '../create/CreateParticipant';
|
||||||
|
|
||||||
@ -34,8 +35,7 @@ export class UpdateDonor extends CreateParticipant {
|
|||||||
donor.email = this.email;
|
donor.email = this.email;
|
||||||
donor.receiptNeeded = this.receiptNeeded;
|
donor.receiptNeeded = this.receiptNeeded;
|
||||||
donor.address = this.address;
|
donor.address = this.address;
|
||||||
|
if (this.receiptNeeded == true && Address.isValidAddress(donor.address) == false) {
|
||||||
if (this.receiptNeeded == true && this.address == null) {
|
|
||||||
throw new DonorReceiptAddressNeededError()
|
throw new DonorReceiptAddressNeededError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,9 @@ export class Address {
|
|||||||
/**
|
/**
|
||||||
* Checks if this is a valid address
|
* Checks if this is a valid address
|
||||||
*/
|
*/
|
||||||
public get isValidAddress(): Boolean {
|
public static isValidAddress(address: Address): Boolean {
|
||||||
if (!this.address1 || !this.city || !this.country || !this.postalcode) { return false; }
|
if (address == null) { return false; }
|
||||||
|
if (address.address1 == null || address.city == null || address.country == null || address.postalcode == null) { return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ describe('Update donor without address but receiptNeeded=true should fail', () =
|
|||||||
it('creating a new donor with only needed params should return 200', async () => {
|
it('creating a new donor with only needed params should return 200', async () => {
|
||||||
const res2 = await axios.post(base + '/api/donors', {
|
const res2 = await axios.post(base + '/api/donors', {
|
||||||
"firstname": "first",
|
"firstname": "first",
|
||||||
"lastname": "last",
|
"lastname": "testtest",
|
||||||
}, axios_config);
|
}, axios_config);
|
||||||
added_donor = res2.data;
|
added_donor = res2.data;
|
||||||
expect(res2.status).toEqual(200);
|
expect(res2.status).toEqual(200);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user