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