Merge branch 'dev' into feature/12-jwt-creation
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { JsonController, Param, Body, Get, Post, Put, Delete, OnUndefined } from 'routing-controllers';
|
||||
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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
||||
import { CreateRunner } from '../models/creation/CreateRunner';
|
||||
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||
|
||||
@JsonController('/runners')
|
||||
//@Authorized('RUNNERS:read')
|
||||
@@ -20,23 +20,29 @@ export class RunnerController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ResponseSchema(Runner, { isArray: true })
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all runners.' })
|
||||
getAll() {
|
||||
return this.runnerRepository.find();
|
||||
async getAll() {
|
||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||
const runners = await this.runnerRepository.find({ relations: ['scans', 'group'] });
|
||||
console.log(runners);
|
||||
runners.forEach(runner => {
|
||||
responseRunners.push(new ResponseRunner(runner));
|
||||
});
|
||||
return responseRunners;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
@ResponseSchema(Runner)
|
||||
@ResponseSchema(ResponseRunner)
|
||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(RunnerNotFoundError)
|
||||
@OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' })
|
||||
getOne(@Param('id') id: number) {
|
||||
return this.runnerRepository.findOne({ id: id });
|
||||
async getOne(@Param('id') id: number) {
|
||||
return new ResponseRunner(await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group'] }));
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ResponseSchema(Runner)
|
||||
@ResponseSchema(ResponseRunner)
|
||||
@ResponseSchema(RunnerOnlyOneGroupAllowedError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@@ -49,11 +55,11 @@ export class RunnerController {
|
||||
return error;
|
||||
}
|
||||
|
||||
return this.runnerRepository.save(runner);
|
||||
return new ResponseRunner(await this.runnerRepository.save(runner));
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
@ResponseSchema(Runner)
|
||||
@ResponseSchema(ResponseRunner)
|
||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a runner object (id can't be changed)." })
|
||||
@@ -69,14 +75,14 @@ export class RunnerController {
|
||||
}
|
||||
|
||||
await this.runnerRepository.update(oldRunner, runner);
|
||||
return runner;
|
||||
return new ResponseRunner(runner);
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
@ResponseSchema(Runner)
|
||||
@ResponseSchema(ResponseRunner)
|
||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
|
||||
async remove(@Param('id') id: number) {
|
||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||
let runner = await this.runnerRepository.findOne({ id: id });
|
||||
|
||||
if (!runner) {
|
||||
@@ -84,6 +90,6 @@ export class RunnerController {
|
||||
}
|
||||
|
||||
await this.runnerRepository.delete(runner);
|
||||
return runner;
|
||||
return new ResponseRunner(runner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { JsonController, Param, Body, Get, Post, Put, Delete, OnUndefined } from 'routing-controllers';
|
||||
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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||
import { RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
||||
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
||||
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';
|
||||
|
||||
|
||||
@JsonController('/organisations')
|
||||
@JsonController('/organisation')
|
||||
//@Authorized('RUNNERS:read')
|
||||
export class RunnerOrganisationController {
|
||||
private runnerOrganisationRepository: Repository<RunnerOrganisation>;
|
||||
@@ -21,23 +25,29 @@ export class RunnerOrganisationController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ResponseSchema(RunnerOrganisation, { isArray: true })
|
||||
@ResponseSchema(ResponseRunnerOrganisation, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all runnerOrganisations.' })
|
||||
getAll() {
|
||||
return this.runnerOrganisationRepository.find();
|
||||
async getAll() {
|
||||
let responseTeams: ResponseRunnerOrganisation[] = new Array<ResponseRunnerOrganisation>();
|
||||
const runners = await this.runnerOrganisationRepository.find({ relations: ['address', 'contact', 'teams'] });
|
||||
console.log(runners);
|
||||
runners.forEach(runner => {
|
||||
responseTeams.push(new ResponseRunnerOrganisation(runner));
|
||||
});
|
||||
return responseTeams;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
@ResponseSchema(RunnerOrganisation)
|
||||
@ResponseSchema(ResponseRunnerOrganisation)
|
||||
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(RunnerOrganisationNotFoundError)
|
||||
@OpenAPI({ description: 'Returns a runnerOrganisation of a specified id (if it exists)' })
|
||||
getOne(@Param('id') id: number) {
|
||||
return this.runnerOrganisationRepository.findOne({ id: id });
|
||||
async getOne(@Param('id') id: number) {
|
||||
return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }));
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ResponseSchema(RunnerOrganisation)
|
||||
@ResponseSchema(ResponseRunnerOrganisation)
|
||||
@OpenAPI({ description: 'Create a new runnerOrganisation object (id will be generated automagicly).' })
|
||||
async post(@Body({ validate: true }) createRunnerOrganisation: CreateRunnerOrganisation) {
|
||||
let runnerOrganisation;
|
||||
@@ -47,16 +57,19 @@ export class RunnerOrganisationController {
|
||||
return error;
|
||||
}
|
||||
|
||||
return this.runnerOrganisationRepository.save(runnerOrganisation);
|
||||
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
|
||||
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
|
||||
|
||||
return new ResponseRunnerOrganisation(runnerOrganisation);
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
@ResponseSchema(RunnerOrganisation)
|
||||
@ResponseSchema(ResponseRunnerOrganisation)
|
||||
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a runnerOrganisation object (id can't be changed)." })
|
||||
async put(@Param('id') id: number, @EntityFromBody() runnerOrganisation: RunnerOrganisation) {
|
||||
let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||
let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
||||
|
||||
if (!oldRunnerOrganisation) {
|
||||
throw new RunnerOrganisationNotFoundError();
|
||||
@@ -67,21 +80,47 @@ export class RunnerOrganisationController {
|
||||
}
|
||||
|
||||
await this.runnerOrganisationRepository.update(oldRunnerOrganisation, runnerOrganisation);
|
||||
return runnerOrganisation;
|
||||
|
||||
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
|
||||
return new ResponseRunnerOrganisation(runnerOrganisation);
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
@ResponseSchema(RunnerOrganisation)
|
||||
@ResponseSchema(ResponseRunnerOrganisation)
|
||||
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 })
|
||||
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
||||
async remove(@Param('id') id: number) {
|
||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) {
|
||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] });
|
||||
|
||||
if (!runnerOrganisation) {
|
||||
throw new RunnerOrganisationNotFoundError();
|
||||
}
|
||||
|
||||
await this.runnerOrganisationRepository.delete(runnerOrganisation);
|
||||
return runnerOrganisation;
|
||||
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) {
|
||||
throw new RunnerOrganisationHasTeamsError();
|
||||
}
|
||||
}
|
||||
const teamController = new RunnerTeamController()
|
||||
teams.forEach(team => {
|
||||
teamController.remove(team.id, true)
|
||||
});
|
||||
|
||||
const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation);
|
||||
await this.runnerOrganisationRepository.delete({ id: runnerOrganisation.id });
|
||||
return responseOrganisation;
|
||||
}
|
||||
}
|
||||
|
||||
113
src/controllers/RunnerTeamController.ts
Normal file
113
src/controllers/RunnerTeamController.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
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 { 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';
|
||||
|
||||
|
||||
@JsonController('/teams')
|
||||
//@Authorized('RUNNERS:read')
|
||||
export class RunnerTeamController {
|
||||
private runnerTeamRepository: Repository<RunnerTeam>;
|
||||
|
||||
/**
|
||||
* Gets the repository of this controller's model/entity.
|
||||
*/
|
||||
constructor() {
|
||||
this.runnerTeamRepository = getConnectionManager().get().getRepository(RunnerTeam);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ResponseSchema(ResponseRunnerTeam, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all runnerTeams.' })
|
||||
async getAll() {
|
||||
let responseTeams: ResponseRunnerTeam[] = new Array<ResponseRunnerTeam>();
|
||||
const runners = await this.runnerTeamRepository.find({ relations: ['parentGroup', 'contact'] });
|
||||
console.log(runners);
|
||||
runners.forEach(runner => {
|
||||
responseTeams.push(new ResponseRunnerTeam(runner));
|
||||
});
|
||||
return responseTeams;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(RunnerTeamNotFoundError)
|
||||
@OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' })
|
||||
async getOne(@Param('id') id: number) {
|
||||
return new ResponseRunnerTeam(await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }));
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
@OpenAPI({ description: 'Create a new runnerTeam object (id will be generated automagicly).' })
|
||||
async post(@Body({ validate: true }) createRunnerTeam: CreateRunnerTeam) {
|
||||
let runnerTeam;
|
||||
try {
|
||||
runnerTeam = await createRunnerTeam.toRunnerTeam();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
runnerTeam = await this.runnerTeamRepository.save(runnerTeam);
|
||||
runnerTeam = await this.runnerTeamRepository.findOne(runnerTeam, { relations: ['parentGroup', 'contact'] });
|
||||
|
||||
return new ResponseRunnerTeam(runnerTeam);
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerTeamIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a runnerTeam object (id can't be changed)." })
|
||||
async put(@Param('id') id: number, @EntityFromBody() runnerTeam: RunnerTeam) {
|
||||
let oldRunnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
|
||||
|
||||
if (!oldRunnerTeam) {
|
||||
throw new RunnerTeamNotFoundError();
|
||||
}
|
||||
|
||||
if (oldRunnerTeam.id != runnerTeam.id) {
|
||||
throw new RunnerTeamIdsNotMatchingError();
|
||||
}
|
||||
|
||||
await this.runnerTeamRepository.update(oldRunnerTeam, runnerTeam);
|
||||
|
||||
runnerTeam = await this.runnerTeamRepository.findOne(runnerTeam, { relations: ['parentGroup', 'contact'] });
|
||||
return new ResponseRunnerTeam(runnerTeam);
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
@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'] });
|
||||
|
||||
if (!runnerTeam) {
|
||||
throw new RunnerTeamNotFoundError();
|
||||
}
|
||||
|
||||
let runners: Runner[] = await runnerTeam.getRunners()
|
||||
if (!force) {
|
||||
if (runners.length != 0) {
|
||||
throw new RunnerTeamHasRunnersError();
|
||||
}
|
||||
}
|
||||
const runnerController = new RunnerController()
|
||||
runners.forEach(runner => {
|
||||
runnerController.remove(runner.id, true)
|
||||
});
|
||||
|
||||
const responseTeam = new ResponseRunnerTeam(runnerTeam);
|
||||
await this.runnerTeamRepository.delete({ id: runnerTeam.id });
|
||||
return responseTeam;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError, Authorized } from 'routing-controllers';
|
||||
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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { Track } from '../models/entities/Track';
|
||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
||||
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
|
||||
import { CreateTrack } from '../models/creation/CreateTrack';
|
||||
import { Track } from '../models/entities/Track';
|
||||
import { ResponseTrack } from '../models/responses/ResponseTrack';
|
||||
|
||||
@JsonController('/tracks')
|
||||
//@Authorized("TRACKS:read")
|
||||
@@ -20,33 +20,38 @@ export class TrackController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ResponseSchema(Track, { isArray: true })
|
||||
@ResponseSchema(ResponseTrack, { isArray: true })
|
||||
@OpenAPI({ description: "Lists all tracks." })
|
||||
getAll() {
|
||||
return this.trackRepository.find();
|
||||
async getAll() {
|
||||
let responseTracks: ResponseTrack[] = new Array<ResponseTrack>();
|
||||
const tracks = await this.trackRepository.find();
|
||||
tracks.forEach(track => {
|
||||
responseTracks.push(new ResponseTrack(track));
|
||||
});
|
||||
return responseTracks;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
@ResponseSchema(Track)
|
||||
@ResponseSchema(ResponseTrack)
|
||||
@ResponseSchema(TrackNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(TrackNotFoundError)
|
||||
@OpenAPI({ description: "Returns a track of a specified id (if it exists)" })
|
||||
getOne(@Param('id') id: number) {
|
||||
return this.trackRepository.findOne({ id: id });
|
||||
async getOne(@Param('id') id: number) {
|
||||
return new ResponseTrack(await this.trackRepository.findOne({ id: id }));
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ResponseSchema(Track)
|
||||
@ResponseSchema(ResponseTrack)
|
||||
@OpenAPI({ description: "Create a new track object (id will be generated automagicly)." })
|
||||
post(
|
||||
async post(
|
||||
@Body({ validate: true })
|
||||
track: CreateTrack
|
||||
) {
|
||||
return this.trackRepository.save(track.toTrack());
|
||||
return new ResponseTrack(await this.trackRepository.save(track.toTrack()));
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
@ResponseSchema(Track)
|
||||
@ResponseSchema(ResponseTrack)
|
||||
@ResponseSchema(TrackNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(TrackIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a track object (id can't be changed)." })
|
||||
@@ -62,11 +67,11 @@ export class TrackController {
|
||||
}
|
||||
|
||||
await this.trackRepository.update(oldTrack, track);
|
||||
return track;
|
||||
return new ResponseTrack(track);
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
@ResponseSchema(Track)
|
||||
@ResponseSchema(ResponseTrack)
|
||||
@ResponseSchema(TrackNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: "Delete a specified track (if it exists)." })
|
||||
async remove(@Param('id') id: number) {
|
||||
@@ -77,6 +82,6 @@ export class TrackController {
|
||||
}
|
||||
|
||||
await this.trackRepository.delete(track);
|
||||
return track;
|
||||
return new ResponseTrack(track);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user