diff --git a/src/models/actions/ImportRunner.ts b/src/models/actions/ImportRunner.ts index 11cac35..3155b0e 100644 --- a/src/models/actions/ImportRunner.ts +++ b/src/models/actions/ImportRunner.ts @@ -75,19 +75,20 @@ export class ImportRunner { throw new RunnerGroupNeededError(); } - let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: groupID }); - if (group instanceof RunnerTeam) { return group; } - if (!(group instanceof RunnerOrganisation) || !group) { + let team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ id: groupID }); + if (team) { return team; } + + let org = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: groupID }); + if (!org) { throw new RunnerOrganisationNotFoundError(); } + if (this.team === undefined) { return org; } - if (this.team === undefined) { return group; } - - let team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ name: this.team, parentGroup: group }); + team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ name: this.team, parentGroup: org }); if (!team) { let newRunnerTeam: RunnerTeam = new RunnerTeam(); newRunnerTeam.name = this.team; - newRunnerTeam.parentGroup = group; + newRunnerTeam.parentGroup = org; team = await getConnectionManager().get().getRepository(RunnerTeam).save(newRunnerTeam); }