Impementing more methods for the runner orgs
This commit is contained in:
parent
330cbd5f57
commit
0c6528bdc5
|
@ -1,11 +1,10 @@
|
||||||
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 { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
|
||||||
import { RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
|
||||||
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
|
||||||
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/organisations')
|
@JsonController('/organisations')
|
||||||
|
@ -74,13 +73,25 @@ export class RunnerOrganisationController {
|
||||||
@ResponseSchema(RunnerOrganisation)
|
@ResponseSchema(RunnerOrganisation)
|
||||||
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
|
||||||
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
|
||||||
async remove(@Param('id') id: number) {
|
async remove(@Param('id') id: number, @QueryParam("force") force) {
|
||||||
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id });
|
||||||
|
|
||||||
if (!runnerOrganisation) {
|
if (!runnerOrganisation) {
|
||||||
throw new RunnerOrganisationNotFoundError();
|
throw new RunnerOrganisationNotFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!force) {
|
||||||
|
if (runnerOrganisation.runners.length != 0) {
|
||||||
|
throw new RunnerOrganisationHasRunnersError();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runnerOrganisation.teams.length != 0) {
|
||||||
|
throw new RunnerOrganisationHasTeamsError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Delete runner and teams
|
||||||
|
|
||||||
await this.runnerOrganisationRepository.delete(runnerOrganisation);
|
await this.runnerOrganisationRepository.delete(runnerOrganisation);
|
||||||
return runnerOrganisation;
|
return runnerOrganisation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError } from 'routing-controllers';
|
import { IsString } from 'class-validator';
|
||||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when a runner couldn't be found.
|
* Error to throw when a runner organisation couldn't be found.
|
||||||
* Implemented this ways to work with the json-schema conversion for openapi.
|
* Implemented this ways to work with the json-schema conversion for openapi.
|
||||||
*/
|
*/
|
||||||
export class RunnerOrganisationNotFoundError extends NotFoundError {
|
export class RunnerOrganisationNotFoundError extends NotFoundError {
|
||||||
|
@ -14,9 +14,9 @@ export class RunnerOrganisationNotFoundError extends NotFoundError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error to throw when two runners' ids don't match.
|
* Error to throw when two runner organisations' ids don't match.
|
||||||
* Usually occurs when a user tries to change a runner's id.
|
* Usually occurs when a user tries to change a runner's id.
|
||||||
* Implemented this ways to work with the json-schema conversion for openapi.
|
* Implemented this way to work with the json-schema conversion for openapi.
|
||||||
*/
|
*/
|
||||||
export class RunnerOrganisationIdsNotMatchingError extends NotAcceptableError {
|
export class RunnerOrganisationIdsNotMatchingError extends NotAcceptableError {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ -24,4 +24,28 @@ export class RunnerOrganisationIdsNotMatchingError extends NotAcceptableError {
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
message = "The id's don't match!! \n And if you wanted to change a runner's id: This isn't allowed"
|
message = "The id's don't match!! \n And if you wanted to change a runner's id: This isn't allowed"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when a organisation still has runners associated.
|
||||||
|
* Implemented this waysto work with the json-schema conversion for openapi.
|
||||||
|
*/
|
||||||
|
export class RunnerOrganisationHasRunnersError extends NotAcceptableError {
|
||||||
|
@IsString()
|
||||||
|
name = "RunnerOrganisationHasRunnersError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "This organisation still has runners associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query."
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to throw when a organisation still has runners associated.
|
||||||
|
* Implemented this waysto work with the json-schema conversion for openapi.
|
||||||
|
*/
|
||||||
|
export class RunnerOrganisationHasTeamsError extends NotAcceptableError {
|
||||||
|
@IsString()
|
||||||
|
name = "RunnerOrganisationHasTeamsError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query."
|
||||||
}
|
}
|
Loading…
Reference in New Issue