Removed useless parts from functions and updated comments

ref #90
This commit is contained in:
Nicolai Ort 2021-01-15 18:20:56 +01:00
parent 9bbfb4763d
commit c05834f2a1
2 changed files with 12 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import { IsInt, IsOptional } from 'class-validator'; import { IsInt, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError, AddressWrongTypeError } from '../../../errors/AddressErrors'; import { AddressNotFoundError } from '../../../errors/AddressErrors';
import { Address } from '../../entities/Address'; import { Address } from '../../entities/Address';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { CreateRunnerGroup } from './CreateRunnerGroup'; import { CreateRunnerGroup } from './CreateRunnerGroup';
@ -10,8 +10,7 @@ import { CreateRunnerGroup } from './CreateRunnerGroup';
*/ */
export class CreateRunnerOrganisation extends CreateRunnerGroup { export class CreateRunnerOrganisation extends CreateRunnerGroup {
/** /**
* The new organisation's address. * The new organisation's address's id.
* Must be of type number (address id).
*/ */
@IsInt() @IsInt()
@IsOptional() @IsOptional()
@ -21,16 +20,10 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
* Gets the org's address by it's id. * Gets the org's address by it's id.
*/ */
public async getAddress(): Promise<Address> { public async getAddress(): Promise<Address> {
if (this.address === undefined || this.address === null) { if (!this.address) { return null; }
return null; let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
} if (!address) { throw new AddressNotFoundError; }
if (!isNaN(this.address)) { return address;
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address });
if (!address) { throw new AddressNotFoundError; }
return address;
}
throw new AddressWrongTypeError;
} }
/** /**
@ -41,7 +34,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
newRunnerOrganisation.name = this.name; newRunnerOrganisation.name = this.name;
newRunnerOrganisation.contact = await this.getContact(); newRunnerOrganisation.contact = await this.getContact();
// newRunnerOrganisation.address = await this.getAddress(); newRunnerOrganisation.address = await this.getAddress();
return newRunnerOrganisation; return newRunnerOrganisation;
} }

View File

@ -1,6 +1,6 @@
import { IsInt, IsNotEmpty } from 'class-validator'; import { IsInt, IsNotEmpty } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { RunnerOrganisationNotFoundError, RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors'; import { RunnerOrganisationNotFoundError } from '../../../errors/RunnerOrganisationErrors';
import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { RunnerTeam } from '../../entities/RunnerTeam'; import { RunnerTeam } from '../../entities/RunnerTeam';
@ -12,7 +12,7 @@ import { CreateRunnerGroup } from './CreateRunnerGroup';
export class CreateRunnerTeam extends CreateRunnerGroup { export class CreateRunnerTeam extends CreateRunnerGroup {
/** /**
* The new team's parent group (organisation). * The new team's parent org's id.
*/ */
@IsInt() @IsInt()
@IsNotEmpty() @IsNotEmpty()
@ -25,13 +25,9 @@ export class CreateRunnerTeam extends CreateRunnerGroup {
if (this.parentGroup === undefined || this.parentGroup === null) { if (this.parentGroup === undefined || this.parentGroup === null) {
throw new RunnerTeamNeedsParentError(); throw new RunnerTeamNeedsParentError();
} }
if (!isNaN(this.parentGroup)) { let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup });
let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup }); if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; }
if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } return parentGroup;
return parentGroup;
}
throw new RunnerOrganisationWrongTypeError;
} }
/** /**
@ -42,7 +38,6 @@ export class CreateRunnerTeam extends CreateRunnerGroup {
newRunnerTeam.name = this.name; newRunnerTeam.name = this.name;
newRunnerTeam.parentGroup = await this.getParent(); newRunnerTeam.parentGroup = await this.getParent();
newRunnerTeam.contact = await this.getContact() newRunnerTeam.contact = await this.getContact()
return newRunnerTeam; return newRunnerTeam;