Merge branch 'dev' of https://git.odit.services/lfk/backend into dev
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
||||
import { CreateRunner } from '../models/creation/CreateRunner';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
@@ -55,7 +55,8 @@ export class RunnerController {
|
||||
return error;
|
||||
}
|
||||
|
||||
return new ResponseRunner(await this.runnerRepository.save(runner));
|
||||
runner = await this.runnerRepository.save(runner)
|
||||
return new ResponseRunner(await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] }));
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
@@ -64,7 +65,7 @@ export class RunnerController {
|
||||
@ResponseSchema(RunnerIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a runner object (id can't be changed)." })
|
||||
async put(@Param('id') id: number, @EntityFromBody() runner: Runner) {
|
||||
let oldRunner = await this.runnerRepository.findOne({ id: id });
|
||||
let oldRunner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group'] });
|
||||
|
||||
if (!oldRunner) {
|
||||
throw new RunnerNotFoundError();
|
||||
@@ -82,14 +83,15 @@ export class RunnerController {
|
||||
@ResponseSchema(ResponseRunner)
|
||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
|
||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||
let runner = await this.runnerRepository.findOne({ id: id });
|
||||
async remove(@EntityFromParam('id') runner: Runner, @QueryParam("force") force: boolean) {
|
||||
if (!runner) { throw new RunnerNotFoundError(); }
|
||||
const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] });
|
||||
|
||||
if (!runner) {
|
||||
throw new RunnerNotFoundError();
|
||||
}
|
||||
|
||||
await this.runnerRepository.delete(runner);
|
||||
return new ResponseRunner(runner);
|
||||
return new ResponseRunner(responseRunner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
||||
import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation';
|
||||
import { RunnerController } from './RunnerController';
|
||||
import { RunnerTeamController } from './RunnerTeamController';
|
||||
@@ -58,9 +56,8 @@ export class RunnerOrganisationController {
|
||||
}
|
||||
|
||||
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
||||
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
|
||||
|
||||
return new ResponseRunnerOrganisation(runnerOrganisation);
|
||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] }));
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
@@ -88,39 +85,35 @@ export class RunnerOrganisationController {
|
||||
@Delete('/:id')
|
||||
@ResponseSchema(ResponseRunnerOrganisation)
|
||||
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
|
||||
@ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 })
|
||||
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
||||
async remove(@EntityFromParam('id') organisation: RunnerOrganisation, @QueryParam("force") force: boolean) {
|
||||
if (!organisation) { throw new RunnerOrganisationNotFoundError() }
|
||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] });
|
||||
|
||||
if (!runnerOrganisation) {
|
||||
throw new RunnerOrganisationNotFoundError();
|
||||
}
|
||||
|
||||
let runners: Runner[] = await runnerOrganisation.getRunners()
|
||||
if (!force) {
|
||||
if (runners.length != 0) {
|
||||
throw new RunnerOrganisationHasRunnersError();
|
||||
}
|
||||
}
|
||||
const runnerController = new RunnerController()
|
||||
runners.forEach(runner => {
|
||||
runnerController.remove(runner.id, true)
|
||||
});
|
||||
|
||||
let teams: RunnerTeam[] = await runnerOrganisation.getTeams()
|
||||
if (!force) {
|
||||
if (teams.length != 0) {
|
||||
if (runnerOrganisation.teams.length != 0) {
|
||||
throw new RunnerOrganisationHasTeamsError();
|
||||
}
|
||||
}
|
||||
const teamController = new RunnerTeamController()
|
||||
teams.forEach(team => {
|
||||
teamController.remove(team.id, true)
|
||||
});
|
||||
for (let team of runnerOrganisation.teams) {
|
||||
await teamController.remove(team, true);
|
||||
}
|
||||
|
||||
if (!force) {
|
||||
if (runnerOrganisation.runners.length != 0) {
|
||||
throw new RunnerOrganisationHasRunnersError();
|
||||
}
|
||||
}
|
||||
const runnerController = new RunnerController()
|
||||
for (let runner of runnerOrganisation.runners) {
|
||||
await runnerController.remove(runner, true);
|
||||
}
|
||||
|
||||
const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation);
|
||||
await this.runnerOrganisationRepository.delete({ id: runnerOrganisation.id });
|
||||
await this.runnerOrganisationRepository.delete(organisation);
|
||||
return responseOrganisation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||
import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors';
|
||||
import { CreateRunnerTeam } from '../models/creation/CreateRunnerTeam';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
||||
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
|
||||
import { RunnerController } from './RunnerController';
|
||||
@@ -88,26 +87,22 @@ export class RunnerTeamController {
|
||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
|
||||
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
|
||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
|
||||
async remove(@EntityFromParam('id') team: RunnerTeam, @QueryParam("force") force: boolean) {
|
||||
if (!team) { throw new RunnerTeamNotFoundError(); }
|
||||
let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] });
|
||||
|
||||
if (!runnerTeam) {
|
||||
throw new RunnerTeamNotFoundError();
|
||||
}
|
||||
|
||||
let runners: Runner[] = await runnerTeam.getRunners()
|
||||
if (!force) {
|
||||
if (runners.length != 0) {
|
||||
if (runnerTeam.runners.length != 0) {
|
||||
throw new RunnerTeamHasRunnersError();
|
||||
}
|
||||
}
|
||||
const runnerController = new RunnerController()
|
||||
runners.forEach(runner => {
|
||||
runnerController.remove(runner.id, true)
|
||||
});
|
||||
for (let runner of runnerTeam.runners) {
|
||||
await runnerController.remove(runner, true);
|
||||
}
|
||||
|
||||
const responseTeam = new ResponseRunnerTeam(runnerTeam);
|
||||
await this.runnerTeamRepository.delete({ id: runnerTeam.id });
|
||||
await this.runnerTeamRepository.delete(team);
|
||||
return responseTeam;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
|
||||
import { CreateTrack } from '../models/creation/CreateTrack';
|
||||
import { Track } from '../models/entities/Track';
|
||||
@@ -74,14 +74,10 @@ export class TrackController {
|
||||
@ResponseSchema(ResponseTrack)
|
||||
@ResponseSchema(TrackNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: "Delete a specified track (if it exists)." })
|
||||
async remove(@Param('id') id: number) {
|
||||
let track = await this.trackRepository.findOne({ id: id });
|
||||
|
||||
if (!track) {
|
||||
throw new TrackNotFoundError();
|
||||
}
|
||||
async remove(@EntityFromParam('id') track: Track) {
|
||||
if (!track) { throw new TrackNotFoundError(); }
|
||||
|
||||
await this.trackRepository.delete(track);
|
||||
return new ResponseTrack(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||
import { UserGroupNotFoundError, UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors';
|
||||
import { CreateUser } from '../models/creation/CreateUser';
|
||||
import { User } from '../models/entities/User';
|
||||
@@ -73,14 +73,12 @@ export class UserController {
|
||||
@ResponseSchema(User)
|
||||
@ResponseSchema(UserNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
|
||||
async remove(@Param('id') id: number) {
|
||||
let runner = await this.userRepository.findOne({ id: id });
|
||||
|
||||
if (!runner) {
|
||||
async remove(@EntityFromParam('id') user: User) {
|
||||
if (!user) {
|
||||
throw new UserNotFoundError();
|
||||
}
|
||||
|
||||
await this.userRepository.delete(runner);
|
||||
return runner;
|
||||
await this.userRepository.delete(user);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
|
||||
import { UserGroupIdsNotMatchingError, UserGroupNotFoundError } from '../errors/UserGroupErrors';
|
||||
import { CreateUserGroup } from '../models/creation/CreateUserGroup';
|
||||
import { UserGroup } from '../models/entities/UserGroup';
|
||||
@@ -73,14 +73,12 @@ export class UserGroupController {
|
||||
@ResponseSchema(UserGroup)
|
||||
@ResponseSchema(UserGroupNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Delete a specified usergroup (if it exists).' })
|
||||
async remove(@Param('id') id: number) {
|
||||
let userGroup = await this.userGroupsRepository.findOne({ id: id });
|
||||
|
||||
if (!userGroup) {
|
||||
async remove(@EntityFromParam('id') group: UserGroup) {
|
||||
if (!group) {
|
||||
throw new UserGroupNotFoundError();
|
||||
}
|
||||
|
||||
await this.userGroupsRepository.delete(userGroup);
|
||||
return userGroup;
|
||||
await this.userGroupsRepository.delete(group);
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user