parent
077174a9a2
commit
8d4c8a4553
@ -1,7 +1,7 @@
|
|||||||
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import { config } from '../../../config';
|
import { config } from '../../../config';
|
||||||
import { AddressNotFoundError, AddressWrongTypeError } from '../../../errors/AddressErrors';
|
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';
|
||||||
|
|
||||||
@ -31,8 +31,7 @@ export class CreateGroupContact {
|
|||||||
lastname: string;
|
lastname: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The new contact's address.
|
* The new contact's address's id.
|
||||||
* Must be the address's id.
|
|
||||||
*/
|
*/
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ -57,16 +56,9 @@ export class CreateGroupContact {
|
|||||||
* Gets the new contact's address by it's id.
|
* Gets the new contact's address by it's id.
|
||||||
*/
|
*/
|
||||||
public async getAddress(): Promise<Address> {
|
public async getAddress(): Promise<Address> {
|
||||||
if (this.address === undefined || this.address === null) {
|
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
||||||
return null;
|
if (!address) { throw new AddressNotFoundError; }
|
||||||
}
|
return address;
|
||||||
if (!isNaN(this.address)) {
|
|
||||||
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
|
||||||
if (!address) { throw new AddressNotFoundError; }
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new AddressWrongTypeError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user