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