Deletes now return 204 instead of 404 (better rest compatability)
ref #13
This commit is contained in:
		@@ -6,6 +6,7 @@ import { RunnerGroupNeededError, RunnerIdsNotMatchingError, RunnerNotFoundError
 | 
			
		||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
 | 
			
		||||
import { CreateRunner } from '../models/actions/CreateRunner';
 | 
			
		||||
import { Runner } from '../models/entities/Runner';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
 | 
			
		||||
 | 
			
		||||
@JsonController('/runners')
 | 
			
		||||
@@ -83,10 +84,11 @@ export class RunnerController {
 | 
			
		||||
 | 
			
		||||
	@Delete('/:id')
 | 
			
		||||
	@ResponseSchema(ResponseRunner)
 | 
			
		||||
	@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@ResponseSchema(ResponseEmpty, { statusCode: 204 })
 | 
			
		||||
	@OnUndefined(204)
 | 
			
		||||
	@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
 | 
			
		||||
	async remove(@EntityFromParam('id') runner: Runner, @QueryParam("force") force: boolean) {
 | 
			
		||||
		if (!runner) { throw new RunnerNotFoundError(); }
 | 
			
		||||
		if (!runner) { return null; }
 | 
			
		||||
		const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] });
 | 
			
		||||
 | 
			
		||||
		if (!runner) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext
 | 
			
		||||
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
 | 
			
		||||
import { CreateRunnerOrganisation } from '../models/actions/CreateRunnerOrganisation';
 | 
			
		||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation';
 | 
			
		||||
import { RunnerController } from './RunnerController';
 | 
			
		||||
import { RunnerTeamController } from './RunnerTeamController';
 | 
			
		||||
@@ -86,12 +87,13 @@ export class RunnerOrganisationController {
 | 
			
		||||
 | 
			
		||||
	@Delete('/:id')
 | 
			
		||||
	@ResponseSchema(ResponseRunnerOrganisation)
 | 
			
		||||
	@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@ResponseSchema(ResponseEmpty, { statusCode: 204 })
 | 
			
		||||
	@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
 | 
			
		||||
	@ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 })
 | 
			
		||||
	@OnUndefined(204)
 | 
			
		||||
	@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
 | 
			
		||||
	async remove(@EntityFromParam('id') organisation: RunnerOrganisation, @QueryParam("force") force: boolean) {
 | 
			
		||||
		if (!organisation) { throw new RunnerOrganisationNotFoundError() }
 | 
			
		||||
		if (!organisation) { return null; }
 | 
			
		||||
		let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] });
 | 
			
		||||
 | 
			
		||||
		if (!force) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext
 | 
			
		||||
import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors';
 | 
			
		||||
import { CreateRunnerTeam } from '../models/actions/CreateRunnerTeam';
 | 
			
		||||
import { RunnerTeam } from '../models/entities/RunnerTeam';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
 | 
			
		||||
import { RunnerController } from './RunnerController';
 | 
			
		||||
 | 
			
		||||
@@ -86,11 +87,12 @@ export class RunnerTeamController {
 | 
			
		||||
 | 
			
		||||
	@Delete('/:id')
 | 
			
		||||
	@ResponseSchema(ResponseRunnerTeam)
 | 
			
		||||
	@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@ResponseSchema(ResponseEmpty, { statusCode: 204 })
 | 
			
		||||
	@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
 | 
			
		||||
	@OnUndefined(204)
 | 
			
		||||
	@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
 | 
			
		||||
	async remove(@EntityFromParam('id') team: RunnerTeam, @QueryParam("force") force: boolean) {
 | 
			
		||||
		if (!team) { throw new RunnerTeamNotFoundError(); }
 | 
			
		||||
		if (!team) { return null; }
 | 
			
		||||
		let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] });
 | 
			
		||||
 | 
			
		||||
		if (!force) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext
 | 
			
		||||
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
 | 
			
		||||
import { CreateTrack } from '../models/actions/CreateTrack';
 | 
			
		||||
import { Track } from '../models/entities/Track';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
import { ResponseTrack } from '../models/responses/ResponseTrack';
 | 
			
		||||
 | 
			
		||||
@JsonController('/tracks')
 | 
			
		||||
@@ -74,10 +75,11 @@ export class TrackController {
 | 
			
		||||
 | 
			
		||||
	@Delete('/:id')
 | 
			
		||||
	@ResponseSchema(ResponseTrack)
 | 
			
		||||
	@ResponseSchema(TrackNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@ResponseSchema(ResponseEmpty, { statusCode: 204 })
 | 
			
		||||
	@OnUndefined(204)
 | 
			
		||||
	@OpenAPI({ description: "Delete a specified track (if it exists)." })
 | 
			
		||||
	async remove(@EntityFromParam('id') track: Track) {
 | 
			
		||||
		if (!track) { throw new TrackNotFoundError(); }
 | 
			
		||||
		if (!track) { return null; }
 | 
			
		||||
 | 
			
		||||
		await this.trackRepository.delete(track);
 | 
			
		||||
		return new ResponseTrack(track);
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import { UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors
 | 
			
		||||
import { UserGroupNotFoundError } from '../errors/UserGroupErrors';
 | 
			
		||||
import { CreateUser } from '../models/actions/CreateUser';
 | 
			
		||||
import { User } from '../models/entities/User';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@JsonController('/users')
 | 
			
		||||
@@ -72,11 +73,12 @@ export class UserController {
 | 
			
		||||
 | 
			
		||||
	@Delete('/:id')
 | 
			
		||||
	@ResponseSchema(User)
 | 
			
		||||
	@ResponseSchema(UserNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@ResponseSchema(ResponseEmpty, { statusCode: 204 })
 | 
			
		||||
	@OnUndefined(204)
 | 
			
		||||
	@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
 | 
			
		||||
	async remove(@EntityFromParam('id') user: User) {
 | 
			
		||||
		if (!user) {
 | 
			
		||||
			throw new UserNotFoundError();
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		await this.userRepository.delete(user);
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext
 | 
			
		||||
import { UserGroupIdsNotMatchingError, UserGroupNotFoundError } from '../errors/UserGroupErrors';
 | 
			
		||||
import { CreateUserGroup } from '../models/actions/CreateUserGroup';
 | 
			
		||||
import { UserGroup } from '../models/entities/UserGroup';
 | 
			
		||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@JsonController('/usergroups')
 | 
			
		||||
@@ -71,11 +72,12 @@ export class UserGroupController {
 | 
			
		||||
 | 
			
		||||
	@Delete('/:id')
 | 
			
		||||
	@ResponseSchema(UserGroup)
 | 
			
		||||
	@ResponseSchema(UserGroupNotFoundError, { statusCode: 404 })
 | 
			
		||||
	@ResponseSchema(ResponseEmpty, { statusCode: 204 })
 | 
			
		||||
	@OnUndefined(204)
 | 
			
		||||
	@OpenAPI({ description: 'Delete a specified usergroup (if it exists).' })
 | 
			
		||||
	async remove(@EntityFromParam('id') group: UserGroup) {
 | 
			
		||||
		if (!group) {
 | 
			
		||||
			throw new UserGroupNotFoundError();
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		await this.userGroupsRepository.delete(group);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user