parent
9b9ee70288
commit
9776a35f9f
@ -101,7 +101,7 @@ export class ScanStationController {
|
|||||||
scanController.remove(scan.id, force);
|
scanController.remove(scan.id, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseStation = await this.stationRepository.findOne({ id: station.id }, { relations: ["track", "scans"] });
|
const responseStation = await this.stationRepository.findOne({ id: station.id }, { relations: ["track"] });
|
||||||
await this.stationRepository.delete(station);
|
await this.stationRepository.delete(station);
|
||||||
return responseStation.toResponse();
|
return responseStation.toResponse();
|
||||||
}
|
}
|
||||||
|
@ -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 { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
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 { CreateTrack } from '../models/actions/CreateTrack';
|
||||||
import { UpdateTrack } from '../models/actions/UpdateTrack';
|
import { UpdateTrack } from '../models/actions/UpdateTrack';
|
||||||
import { Track } from '../models/entities/Track';
|
import { Track } from '../models/entities/Track';
|
||||||
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
import { ResponseEmpty } from '../models/responses/ResponseEmpty';
|
||||||
import { ResponseTrack } from '../models/responses/ResponseTrack';
|
import { ResponseTrack } from '../models/responses/ResponseTrack';
|
||||||
|
import { ScanStationController } from './ScanStationController';
|
||||||
|
|
||||||
@JsonController('/tracks')
|
@JsonController('/tracks')
|
||||||
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
||||||
@ -85,10 +86,19 @@ export class TrackController {
|
|||||||
@ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
@ResponseSchema(ResponseEmpty, { statusCode: 204 })
|
||||||
@OnUndefined(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)." })
|
@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 });
|
let track = await this.trackRepository.findOne({ id: id });
|
||||||
if (!track) { return null; }
|
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);
|
await this.trackRepository.delete(track);
|
||||||
return new ResponseTrack(track);
|
return new ResponseTrack(track);
|
||||||
}
|
}
|
||||||
|
@ -34,3 +34,11 @@ export class TrackLapTimeCantBeNegativeError extends NotAcceptableError {
|
|||||||
@IsString()
|
@IsString()
|
||||||
message = "The minimum lap time you provided is negative - That isn't possible. \n If you wanted to disable it: Just set it to 0/null."
|
message = "The minimum lap time you provided is negative - That isn't possible. \n If you wanted to disable it: Just set it to 0/null."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class TrackHasScanStationsError extends NotAcceptableError {
|
||||||
|
@IsString()
|
||||||
|
name = "TrackHasScanStationsError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "This track still has stations associated with it. \n If you want to delete this track with all it's stations and scans add `?force` to your query."
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user