parent
8d4c8a4553
commit
644d2b06ac
@ -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';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,26 +47,18 @@ export abstract class CreateParticipant {
|
|||||||
email?: string;
|
email?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The new participant's address.
|
* The new participant's address's id.
|
||||||
* Must be of type number (address id).
|
|
||||||
*/
|
*/
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
address?: number;
|
address?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the new participant's address by it's address.
|
* Gets the new participant's address by it's id.
|
||||||
*/
|
*/
|
||||||
public async getAddress(): Promise<Address> {
|
public async getAddress(): Promise<Address> {
|
||||||
if (this.address === undefined || this.address === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!isNaN(this.address)) {
|
|
||||||
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
|
||||||
if (!address) { throw new AddressNotFoundError; }
|
if (!address) { throw new AddressNotFoundError; }
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new AddressWrongTypeError;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user