parent
8dbee32eee
commit
4824547dde
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 () => {
|
||||
const res2 = await axios.post(base + '/api/donors', {
|
||||
"firstname": "first",
|
||||
"lastname": "last",
|
||||
"lastname": "testtest",
|
||||
}, axios_config);
|
||||
added_donor = res2.data;
|
||||
expect(res2.status).toEqual(200);
|
||||
|
|
Loading…
Reference in New Issue