From 2cd15d25e934a5439bfea4de901f136e360e17f6 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sat, 16 Jan 2021 16:55:30 +0100 Subject: [PATCH] Switched the create classes over to the new address implementation ref #105 --- src/models/actions/create/CreateDonor.ts | 2 +- .../actions/create/CreateGroupContact.ts | 19 ++++-------------- .../actions/create/CreateParticipant.ts | 18 +++-------------- src/models/actions/create/CreateRunner.ts | 2 +- .../create/CreateRunnerOrganisation.ts | 20 ++++--------------- 5 files changed, 13 insertions(+), 48 deletions(-) diff --git a/src/models/actions/create/CreateDonor.ts b/src/models/actions/create/CreateDonor.ts index 791461a..a99d139 100644 --- a/src/models/actions/create/CreateDonor.ts +++ b/src/models/actions/create/CreateDonor.ts @@ -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() diff --git a/src/models/actions/create/CreateGroupContact.ts b/src/models/actions/create/CreateGroupContact.ts index b9a9d41..f74d633 100644 --- a/src/models/actions/create/CreateGroupContact.ts +++ b/src/models/actions/create/CreateGroupContact.ts @@ -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
{ - 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; } } \ No newline at end of file diff --git a/src/models/actions/create/CreateParticipant.ts b/src/models/actions/create/CreateParticipant.ts index 6518666..16ef7cc 100644 --- a/src/models/actions/create/CreateParticipant.ts +++ b/src/models/actions/create/CreateParticipant.ts @@ -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
{ - 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; } \ No newline at end of file diff --git a/src/models/actions/create/CreateRunner.ts b/src/models/actions/create/CreateRunner.ts index 2286fdf..83d9ca9 100644 --- a/src/models/actions/create/CreateRunner.ts +++ b/src/models/actions/create/CreateRunner.ts @@ -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; } diff --git a/src/models/actions/create/CreateRunnerOrganisation.ts b/src/models/actions/create/CreateRunnerOrganisation.ts index 1938eee..eba73b6 100644 --- a/src/models/actions/create/CreateRunnerOrganisation.ts +++ b/src/models/actions/create/CreateRunnerOrganisation.ts @@ -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
{ - 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; }