Switched to accepting ids (numbers/number arrays) feature/90-accept_objects #101

Merged
niggl merged 26 commits from feature/90-accept_objects into dev 2021-01-15 17:57:47 +00:00
Showing only changes of commit bae8290273 - Show all commits

View File

@ -1,4 +1,4 @@
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
import { IsBoolean, IsInt, IsOptional, IsPositive } from 'class-validator';
import { getConnection } from 'typeorm';
import { RunnerNotFoundError } from '../../../errors/RunnerErrors';
import { ScanStationNotFoundError } from '../../../errors/ScanStationErrors';
@ -22,8 +22,8 @@ export abstract class UpdateTrackScan {
* This is important to link ran distances to runners.
*/
@IsInt()
@IsOptional()
runner?: number;
@IsPositive()
runner: number;
/**
* Is the updated scan valid (for fraud reasons).
@ -37,8 +37,8 @@ export abstract class UpdateTrackScan {
* This is important to link ran distances to runners.
*/
@IsInt()
@IsOptional()
public station?: number;
@IsPositive()
public station: number;
/**
* Update a TrackScan entity based on this.
@ -46,12 +46,8 @@ export abstract class UpdateTrackScan {
*/
public async update(scan: TrackScan): Promise<TrackScan> {
scan.valid = this.valid;
if (this.runner) {
scan.runner = await this.getRunner();
}
if (this.station) {
scan.station = await this.getStation();
}
scan.track = scan.station.track;
return scan;
@ -72,7 +68,7 @@ export abstract class UpdateTrackScan {
* Gets a runner based on the runner id provided via this.runner.
*/
public async getStation(): Promise<ScanStation> {
const station = await getConnection().getRepository(ScanStation).findOne({ id: this.station });
const station = await getConnection().getRepository(ScanStation).findOne({ id: this.station }, { relations: ['track'] });
if (!station) {
throw new ScanStationNotFoundError();
}