parent
d89fcb84a2
commit
ebb0c5faca
@ -1,9 +1,9 @@
|
|||||||
import { Get, JsonController } from 'routing-controllers';
|
import { Get, JsonController, OnUndefined, Param } 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 { Permission } from '../models/entities/Permission';
|
import { Permission } from '../models/entities/Permission';
|
||||||
import { ResponsePermission } from '../models/responses/ResponsePermission';
|
import { ResponsePermission } from '../models/responses/ResponsePermission';
|
||||||
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
|
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/permissions')
|
@JsonController('/permissions')
|
||||||
@ -19,8 +19,8 @@ export class PermissionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ResponseSchema(ResponseRunnerTeam, { isArray: true })
|
@ResponseSchema(ResponsePermission, { isArray: true })
|
||||||
@OpenAPI({ description: 'Lists all runnerTeams.' })
|
@OpenAPI({ description: 'Lists all permissions.' })
|
||||||
async getAll() {
|
async getAll() {
|
||||||
let responsePermissions: ResponsePermission[] = new Array<ResponsePermission>();
|
let responsePermissions: ResponsePermission[] = new Array<ResponsePermission>();
|
||||||
const permissions = await this.permissionController.find({ relations: ['principal'] });
|
const permissions = await this.permissionController.find({ relations: ['principal'] });
|
||||||
@ -30,18 +30,19 @@ export class PermissionController {
|
|||||||
return responsePermissions;
|
return responsePermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
@ResponseSchema(ResponseRunnerTeam)
|
@ResponseSchema(ResponsePermission)
|
||||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
@ResponseSchema(PermissionNotFoundError, { statusCode: 404 })
|
||||||
@OnUndefined(RunnerTeamNotFoundError)
|
@OnUndefined(PermissionNotFoundError)
|
||||||
@OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' })
|
@OpenAPI({ description: 'Returns a permissions of a specified id (if it exists)' })
|
||||||
async getOne(@Param('id') id: number) {
|
async getOne(@Param('id') id: number) {
|
||||||
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] });
|
let permission = await this.permissionController.findOne({ id: id }, { relations: ['principal'] });
|
||||||
if (!runnerTeam) { throw new RunnerTeamNotFoundError(); }
|
if (!permission) { throw new PermissionNotFoundError(); }
|
||||||
return new ResponseRunnerTeam(runnerTeam);
|
return new ResponsePermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Post()
|
@Post()
|
||||||
@ResponseSchema(ResponseRunnerTeam)
|
@ResponseSchema(ResponseRunnerTeam)
|
||||||
@OpenAPI({ description: 'Create a new runnerTeam object (id will be generated automagicly).' })
|
@OpenAPI({ description: 'Create a new runnerTeam object (id will be generated automagicly).' })
|
||||||
@ -58,7 +59,7 @@ export class PermissionController {
|
|||||||
|
|
||||||
return new ResponseRunnerTeam(runnerTeam);
|
return new ResponseRunnerTeam(runnerTeam);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
@ResponseSchema(ResponseRunnerTeam)
|
@ResponseSchema(ResponseRunnerTeam)
|
||||||
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
|
||||||
|
25
src/errors/PermissionErrors.ts
Normal file
25
src/errors/PermissionErrors.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
||||||
|
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when a permission couldn't be found.
|
||||||
|
*/
|
||||||
|
export class PermissionNotFoundError extends NotFoundError {
|
||||||
|
@IsString()
|
||||||
|
name = "PermissionNotFoundError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "Permission not found!"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when two permission' ids don't match.
|
||||||
|
* Usually occurs when a user tries to change a permission's id.
|
||||||
|
*/
|
||||||
|
export class PermissionIdsNotMatchingError extends NotAcceptableError {
|
||||||
|
@IsString()
|
||||||
|
name = "PermissionIdsNotMatchingError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "The id's don't match!! \n And if you wanted to change a permission's id: This isn't allowed"
|
||||||
|
}
|
13
src/errors/PrincipalsErrors.ts
Normal file
13
src/errors/PrincipalsErrors.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
||||||
|
import { NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when a user couldn't be found.
|
||||||
|
*/
|
||||||
|
export class PrincipalNotFoundError extends NotFoundError {
|
||||||
|
@IsString()
|
||||||
|
name = "PrincipalNotFoundError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "Principal not found!"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user