Switched the create classes over to the new address implementation
ref #105
This commit is contained in:
		@@ -26,8 +26,8 @@ export class CreateDonor extends CreateParticipant {
 | 
			
		||||
        newDonor.lastname = this.lastname;
 | 
			
		||||
        newDonor.phone = this.phone;
 | 
			
		||||
        newDonor.email = this.email;
 | 
			
		||||
        newDonor.address = await this.getAddress();
 | 
			
		||||
        newDonor.receiptNeeded = this.receiptNeeded;
 | 
			
		||||
        newDonor.address = this.address;
 | 
			
		||||
 | 
			
		||||
        if (this.receiptNeeded == true && this.address == null) {
 | 
			
		||||
            throw new DonorReceiptAddressNeededError()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
 | 
			
		||||
import { getConnectionManager } from 'typeorm';
 | 
			
		||||
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
 | 
			
		||||
import { config } from '../../../config';
 | 
			
		||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
 | 
			
		||||
import { Address } from '../../entities/Address';
 | 
			
		||||
import { GroupContact } from '../../entities/GroupContact';
 | 
			
		||||
 | 
			
		||||
@@ -33,9 +31,9 @@ export class CreateGroupContact {
 | 
			
		||||
    /**
 | 
			
		||||
     * The new contact's address's id.
 | 
			
		||||
     */
 | 
			
		||||
    @IsInt()
 | 
			
		||||
    @IsOptional()
 | 
			
		||||
    address?: number;
 | 
			
		||||
    @IsObject()
 | 
			
		||||
    address?: Address;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The contact's phone number.
 | 
			
		||||
@@ -52,15 +50,6 @@ export class CreateGroupContact {
 | 
			
		||||
    @IsEmail()
 | 
			
		||||
    email?: string;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the new contact's address by it's id.
 | 
			
		||||
     */
 | 
			
		||||
    public async getAddress(): Promise<Address> {
 | 
			
		||||
        if (!this.address) { return null; }
 | 
			
		||||
        let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
 | 
			
		||||
        if (!address) { throw new AddressNotFoundError; }
 | 
			
		||||
        return address;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a new Address entity from this.
 | 
			
		||||
@@ -72,7 +61,7 @@ export class CreateGroupContact {
 | 
			
		||||
        contact.lastname = this.lastname;
 | 
			
		||||
        contact.email = this.email;
 | 
			
		||||
        contact.phone = this.phone;
 | 
			
		||||
        contact.address = await this.getAddress();
 | 
			
		||||
        contact.address = this.address;
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
 | 
			
		||||
import { getConnectionManager } from 'typeorm';
 | 
			
		||||
import { IsEmail, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
 | 
			
		||||
import { config } from '../../../config';
 | 
			
		||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
 | 
			
		||||
import { Address } from '../../entities/Address';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -49,17 +47,7 @@ export abstract class CreateParticipant {
 | 
			
		||||
    /**
 | 
			
		||||
     * The new participant's address's id.
 | 
			
		||||
     */
 | 
			
		||||
    @IsInt()
 | 
			
		||||
    @IsOptional()
 | 
			
		||||
    address?: number;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the new participant's address by it's id.
 | 
			
		||||
     */
 | 
			
		||||
    public async getAddress(): Promise<Address> {
 | 
			
		||||
        if (!this.address) { return null; }
 | 
			
		||||
        let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
 | 
			
		||||
        if (!address) { throw new AddressNotFoundError; }
 | 
			
		||||
        return address;
 | 
			
		||||
    }
 | 
			
		||||
    @IsObject()
 | 
			
		||||
    address?: Address;
 | 
			
		||||
}
 | 
			
		||||
@@ -30,7 +30,7 @@ export class CreateRunner extends CreateParticipant {
 | 
			
		||||
        newRunner.phone = this.phone;
 | 
			
		||||
        newRunner.email = this.email;
 | 
			
		||||
        newRunner.group = await this.getGroup();
 | 
			
		||||
        newRunner.address = await this.getAddress();
 | 
			
		||||
        newRunner.address = this.address;
 | 
			
		||||
 | 
			
		||||
        return newRunner;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,4 @@
 | 
			
		||||
import { IsInt, IsOptional } from 'class-validator';
 | 
			
		||||
import { getConnectionManager } from 'typeorm';
 | 
			
		||||
import { AddressNotFoundError } from '../../../errors/AddressErrors';
 | 
			
		||||
import { IsObject, IsOptional } from 'class-validator';
 | 
			
		||||
import { Address } from '../../entities/Address';
 | 
			
		||||
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
 | 
			
		||||
import { CreateRunnerGroup } from './CreateRunnerGroup';
 | 
			
		||||
@@ -12,19 +10,9 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
 | 
			
		||||
    /**
 | 
			
		||||
     * The new organisation's address's id.
 | 
			
		||||
     */
 | 
			
		||||
    @IsInt()
 | 
			
		||||
    @IsOptional()
 | 
			
		||||
    address?: number;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the org's address by it's id.
 | 
			
		||||
     */
 | 
			
		||||
    public async getAddress(): Promise<Address> {
 | 
			
		||||
        if (!this.address) { return null; }
 | 
			
		||||
        let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
 | 
			
		||||
        if (!address) { throw new AddressNotFoundError; }
 | 
			
		||||
        return address;
 | 
			
		||||
    }
 | 
			
		||||
    @IsObject()
 | 
			
		||||
    address?: Address;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a new RunnerOrganisation entity from this.
 | 
			
		||||
@@ -34,7 +22,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
 | 
			
		||||
 | 
			
		||||
        newRunnerOrganisation.name = this.name;
 | 
			
		||||
        newRunnerOrganisation.contact = await this.getContact();
 | 
			
		||||
        newRunnerOrganisation.address = await this.getAddress();
 | 
			
		||||
        newRunnerOrganisation.address = this.address;
 | 
			
		||||
 | 
			
		||||
        return newRunnerOrganisation;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user