Refactoring: switched update team parent from objects to ids

ref #90
This commit is contained in:
Nicolai Ort 2021-01-15 18:31:23 +01:00
parent 97c01ce81a
commit ed3b55a1e2
1 changed files with 9 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import { IsInt, IsNotEmpty, IsObject } from 'class-validator';
import { IsInt, IsPositive } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { RunnerOrganisationNotFoundError, RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors';
import { RunnerOrganisationNotFoundError } from '../../../errors/RunnerOrganisationErrors';
import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { RunnerTeam } from '../../entities/RunnerTeam';
@ -19,12 +19,11 @@ export class UpdateRunnerTeam extends CreateRunnerGroup {
id: number;
/**
* The updated team's parentGroup.
* Just has to contain the organisation's id - everything else won't be checked or changed.
* The updated team's parentGroup's id.
*/
@IsObject()
@IsNotEmpty()
parentGroup: RunnerOrganisation;
@IsInt()
@IsPositive()
parentGroup: number;
/**
* Loads the updated teams's parentGroup based on it's id.
@ -33,13 +32,9 @@ export class UpdateRunnerTeam extends CreateRunnerGroup {
if (this.parentGroup === undefined || this.parentGroup === null) {
throw new RunnerTeamNeedsParentError();
}
if (!isNaN(this.parentGroup.id)) {
let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup.id });
if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; }
return parentGroup;
}
throw new RunnerOrganisationWrongTypeError;
let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup });
if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; }
return parentGroup;
}
/**