Switched the create classes over to the new address implementation

ref #105
This commit is contained in:
2021-01-16 16:55:30 +01:00
parent dafac06bc8
commit 2cd15d25e9
5 changed files with 13 additions and 48 deletions

View File

@@ -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;
}
}