parent
145a08b1b4
commit
d4293c164d
|
@ -1,9 +1,11 @@
|
|||
import { Body, Get, JsonController, OnUndefined, Param, Post } from 'routing-controllers';
|
||||
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, QueryParam } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { PermissionNotFoundError } from '../errors/PermissionErrors';
|
||||
import { PrincipalNotFoundError } from '../errors/PrincipalsErrors';
|
||||
import { CreatePermission } from '../models/actions/CreatePermission';
|
||||
import { Permission } from '../models/entities/Permission';
|
||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||
import { ResponsePermission } from '../models/responses/ResponsePermission';
|
||||
|
||||
|
||||
|
@ -46,6 +48,7 @@ export class PermissionController {
|
|||
|
||||
@Post()
|
||||
@ResponseSchema(ResponsePermission)
|
||||
@ResponseSchema(PrincipalNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Create a new runnerTeam object (id will be generated automagicly).' })
|
||||
async post(@Body({ validate: true }) createPermission: CreatePermission) {
|
||||
let permission;
|
||||
|
@ -60,52 +63,40 @@ export class PermissionController {
|
|||
|
||||
return new ResponsePermission(permission);
|
||||
}
|
||||
|
||||
/*
|
||||
@Put('/:id')
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(RunnerTeamIdsNotMatchingError, { statusCode: 406 })
|
||||
@ResponseSchema(ResponsePrincipal)
|
||||
@ResponseSchema(PermissionNotFoundError, { statusCode: 404 })
|
||||
@ResponseSchema(PermissionIdsNotMatchingError, { statusCode: 406 })
|
||||
@OpenAPI({ description: "Update a runnerTeam object (id can't be changed)." })
|
||||
async put(@Param('id') id: number, @Body({ validate: true }) runnerTeam: UpdateRunnerTeam) {
|
||||
let oldRunnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
|
||||
async put(@Param('id') id: number, @EntityFromBody() permission: Permission) {
|
||||
let oldPermission = await this.permissionRepository.findOne({ id: id }, { relations: ['principal'] });
|
||||
|
||||
if (!oldRunnerTeam) {
|
||||
throw new RunnerTeamNotFoundError();
|
||||
if (!oldPermission) {
|
||||
throw new PermissionNotFoundError();
|
||||
}
|
||||
|
||||
if (oldRunnerTeam.id != runnerTeam.id) {
|
||||
throw new RunnerTeamIdsNotMatchingError();
|
||||
if (oldPermission.id != permission.id) {
|
||||
throw new PermissionIdsNotMatchingError();
|
||||
}
|
||||
|
||||
await this.runnerTeamRepository.update(oldRunnerTeam, await runnerTeam.toRunnerTeam());
|
||||
await this.permissionRepository.update(oldPermission, permission);
|
||||
|
||||
return new ResponseRunnerTeam(await this.runnerTeamRepository.findOne({ id: runnerTeam.id }, { relations: ['parentGroup', 'contact'] }));
|
||||
}
|
||||
return new ResponsePermission(await this.permissionRepository.findOne({ id: permission.id }, { relations: ['principal'] }));
|
||||
}*/
|
||||
|
||||
@Delete('/:id')
|
||||
@ResponseSchema(ResponseRunnerTeam)
|
||||
@ResponseSchema(ResponsePermission)
|
||||
@ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
||||
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
|
||||
@OnUndefined(204)
|
||||
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
|
||||
@OpenAPI({ description: 'Delete a specified permission (if it exists).' })
|
||||
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
|
||||
let team = await this.runnerTeamRepository.findOne({ id: id });
|
||||
if (!team) { return null; }
|
||||
let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] });
|
||||
let permission = await this.permissionRepository.findOne({ id: id }, { relations: ['principal'] });
|
||||
if (!permission) { return null; }
|
||||
|
||||
if (!force) {
|
||||
if (runnerTeam.runners.length != 0) {
|
||||
throw new RunnerTeamHasRunnersError();
|
||||
}
|
||||
}
|
||||
const runnerController = new RunnerController()
|
||||
for (let runner of runnerTeam.runners) {
|
||||
await runnerController.remove(runner.id, true);
|
||||
}
|
||||
|
||||
const responseTeam = new ResponseRunnerTeam(runnerTeam);
|
||||
await this.runnerTeamRepository.delete(team);
|
||||
return responseTeam;
|
||||
const responsePermission = new ResponsePermission(permission);
|
||||
await this.permissionRepository.delete(permission);
|
||||
return responsePermission;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue