| 
							
							
							
						 |  |  | @@ -1,12 +1,13 @@ | 
		
	
		
			
				|  |  |  |  | import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers'; | 
		
	
		
			
				|  |  |  |  | import { Authorized, 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 { TrackIdsNotMatchingError, TrackLapTimeCantBeNegativeError, TrackNotFoundError } from "../errors/TrackErrors"; | 
		
	
		
			
				|  |  |  |  | import { TrackHasScanStationsError, TrackIdsNotMatchingError, TrackLapTimeCantBeNegativeError, TrackNotFoundError } from "../errors/TrackErrors"; | 
		
	
		
			
				|  |  |  |  | import { CreateTrack } from '../models/actions/CreateTrack'; | 
		
	
		
			
				|  |  |  |  | import { UpdateTrack } from '../models/actions/UpdateTrack'; | 
		
	
		
			
				|  |  |  |  | import { Track } from '../models/entities/Track'; | 
		
	
		
			
				|  |  |  |  | import { ResponseEmpty } from '../models/responses/ResponseEmpty'; | 
		
	
		
			
				|  |  |  |  | import { ResponseTrack } from '../models/responses/ResponseTrack'; | 
		
	
		
			
				|  |  |  |  | import { ScanStationController } from './ScanStationController'; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | @JsonController('/tracks') | 
		
	
		
			
				|  |  |  |  | @OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) | 
		
	
	
		
			
				
					
					|  |  |  | @@ -85,10 +86,19 @@ export class TrackController { | 
		
	
		
			
				|  |  |  |  | 	@ResponseSchema(ResponseEmpty, { statusCode: 204 }) | 
		
	
		
			
				|  |  |  |  | 	@OnUndefined(204) | 
		
	
		
			
				|  |  |  |  | 	@OpenAPI({ description: "Delete the track whose id you provided. <br> If no track with this id exists it will just return 204(no content)." }) | 
		
	
		
			
				|  |  |  |  | 	async remove(@Param("id") id: number) { | 
		
	
		
			
				|  |  |  |  | 	async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { | 
		
	
		
			
				|  |  |  |  | 		let track = await this.trackRepository.findOne({ id: id }); | 
		
	
		
			
				|  |  |  |  | 		if (!track) { return null; } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 		const trackStations = (await this.trackRepository.findOne({ id: id }, { relations: ["stations"] })).stations; | 
		
	
		
			
				|  |  |  |  | 		if (trackStations.length != 0 && !force) { | 
		
	
		
			
				|  |  |  |  | 			throw new TrackHasScanStationsError(); | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 		const scanController = new ScanStationController; | 
		
	
		
			
				|  |  |  |  | 		for (let station of trackStations) { | 
		
	
		
			
				|  |  |  |  | 			scanController.remove(station.id, force); | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 		await this.trackRepository.delete(track); | 
		
	
		
			
				|  |  |  |  | 		return new ResponseTrack(track); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
	
		
			
				
					
					| 
							
							
							
						 |  |  |   |