| @@ -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 { getConnectionManager, Repository } from 'typeorm'; | ||||
| import { PermissionNotFoundError } from '../errors/PermissionErrors'; | ||||
| import { Permission } from '../models/entities/Permission'; | ||||
| import { ResponsePermission } from '../models/responses/ResponsePermission'; | ||||
| import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam'; | ||||
|  | ||||
|  | ||||
| @JsonController('/permissions') | ||||
| @@ -19,8 +19,8 @@ export class PermissionController { | ||||
|     } | ||||
|  | ||||
|     @Get() | ||||
|     @ResponseSchema(ResponseRunnerTeam, { isArray: true }) | ||||
|     @OpenAPI({ description: 'Lists all runnerTeams.' }) | ||||
|     @ResponseSchema(ResponsePermission, { isArray: true }) | ||||
|     @OpenAPI({ description: 'Lists all permissions.' }) | ||||
|     async getAll() { | ||||
|         let responsePermissions: ResponsePermission[] = new Array<ResponsePermission>(); | ||||
|         const permissions = await this.permissionController.find({ relations: ['principal'] }); | ||||
| @@ -30,18 +30,19 @@ export class PermissionController { | ||||
|         return responsePermissions; | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|  | ||||
|     @Get('/:id') | ||||
|     @ResponseSchema(ResponseRunnerTeam) | ||||
|     @ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 }) | ||||
|     @OnUndefined(RunnerTeamNotFoundError) | ||||
|     @OpenAPI({ description: 'Returns a runnerTeam of a specified id (if it exists)' }) | ||||
|     @ResponseSchema(ResponsePermission) | ||||
|     @ResponseSchema(PermissionNotFoundError, { statusCode: 404 }) | ||||
|     @OnUndefined(PermissionNotFoundError) | ||||
|     @OpenAPI({ description: 'Returns a permissions of a specified id (if it exists)' }) | ||||
|     async getOne(@Param('id') id: number) { | ||||
|         let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }); | ||||
|         if (!runnerTeam) { throw new RunnerTeamNotFoundError(); } | ||||
|         return new ResponseRunnerTeam(runnerTeam); | ||||
|         let permission = await this.permissionController.findOne({ id: id }, { relations: ['principal'] }); | ||||
|         if (!permission) { throw new PermissionNotFoundError(); } | ||||
|         return new ResponsePermission(permission); | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|     @Post() | ||||
|     @ResponseSchema(ResponseRunnerTeam) | ||||
|     @OpenAPI({ description: 'Create a new runnerTeam object (id will be generated automagicly).' }) | ||||
| @@ -58,7 +59,7 @@ export class PermissionController { | ||||
|  | ||||
|         return new ResponseRunnerTeam(runnerTeam); | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|     @Put('/:id') | ||||
|     @ResponseSchema(ResponseRunnerTeam) | ||||
|     @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!" | ||||
| } | ||||
		Reference in New Issue
	
	Block a user