Fixed some stuff not getting checked against null

ref #39 gosh i sometimes hate js types
This commit is contained in:
2020-12-20 18:18:32 +01:00
parent fbe2b358bd
commit 7a4238f1f7
10 changed files with 15 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
import { IsInt, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors';
import { AddressNotFoundError } from '../../errors/AddressErrors';
import { Address } from '../entities/Address';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { CreateRunnerGroup } from './CreateRunnerGroup';
@@ -20,22 +20,18 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
*/
@IsInt()
@IsOptional()
address?: number;
address?: Address;
/**
* Get's this org's address from this.address.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined) {
if (this.address === undefined || this.address === null) {
return null;
}
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;
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address.id });
if (!address) { throw new AddressNotFoundError; }
return address;
}
/**