Compare commits

..

No commits in common. "6249419fae22e0203c046c1a3cd82c07f94f510c" and "a6bca59ffe06a37f03af21500c442cebeaa74c7e" have entirely different histories.

2 changed files with 16 additions and 15 deletions

View File

@ -1,9 +1,9 @@
import { IsBoolean, IsInt, IsOptional, IsPositive } from 'class-validator'; import { IsBoolean, IsInt, IsOptional, IsPositive } from 'class-validator';
import { getConnection } from 'typeorm'; import { getConnection } from 'typeorm';
import { RunnerNotFoundError } from '../../../errors/RunnerErrors'; import { RunnerNotFoundError } from '../../../errors/RunnerErrors';
import { TrackNotFoundError } from '../../../errors/TrackErrors'; import { ScanStationNotFoundError } from '../../../errors/ScanStationErrors';
import { Runner } from '../../entities/Runner'; import { Runner } from '../../entities/Runner';
import { Track } from '../../entities/Track'; import { ScanStation } from '../../entities/ScanStation';
import { TrackScan } from '../../entities/TrackScan'; import { TrackScan } from '../../entities/TrackScan';
/** /**
@ -38,7 +38,7 @@ export abstract class UpdateTrackScan {
*/ */
@IsInt() @IsInt()
@IsPositive() @IsPositive()
public track: number; public station: number;
/** /**
* Update a TrackScan entity based on this. * Update a TrackScan entity based on this.
@ -47,7 +47,8 @@ export abstract class UpdateTrackScan {
public async update(scan: TrackScan): Promise<TrackScan> { public async update(scan: TrackScan): Promise<TrackScan> {
scan.valid = this.valid; scan.valid = this.valid;
scan.runner = await this.getRunner(); scan.runner = await this.getRunner();
scan.track = await this.getTrack(); scan.station = await this.getStation();
scan.track = scan.station.track;
return scan; return scan;
} }
@ -66,11 +67,11 @@ export abstract class UpdateTrackScan {
/** /**
* Gets a runner based on the runner id provided via this.runner. * Gets a runner based on the runner id provided via this.runner.
*/ */
public async getTrack(): Promise<Track> { public async getStation(): Promise<ScanStation> {
const track = await getConnection().getRepository(Track).findOne({ id: this.track }); const station = await getConnection().getRepository(ScanStation).findOne({ id: this.station }, { relations: ['track'] });
if (!track) { if (!station) {
throw new TrackNotFoundError(); throw new ScanStationNotFoundError();
} }
return track; return station;
} }
} }

View File

@ -86,7 +86,7 @@ describe('adding + updating illegally', () => {
it('updating with wrong id should return 406', async () => { it('updating with wrong id should return 406', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, { const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id + 1, "id": added_scan.id + 1,
"track": added_track.id, "station": added_station.id,
"runner": added_runner.id "runner": added_runner.id
}, axios_config); }, axios_config);
expect(res2.status).toEqual(406); expect(res2.status).toEqual(406);
@ -95,7 +95,7 @@ describe('adding + updating illegally', () => {
it('updating with invalid station should return 404', async () => { it('updating with invalid station should return 404', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, { const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id, "id": added_scan.id,
"track": 9999999999999999, "station": 9999999999999999,
"runner": added_runner.id "runner": added_runner.id
}, axios_config); }, axios_config);
expect(res2.status).toEqual(404); expect(res2.status).toEqual(404);
@ -104,7 +104,7 @@ describe('adding + updating illegally', () => {
it('updating with invalid runner should return 404', async () => { it('updating with invalid runner should return 404', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, { const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id, "id": added_scan.id,
"track": added_station.id, "station": added_station.id,
"runner": 9999999999999999999 "runner": 9999999999999999999
}, axios_config); }, axios_config);
expect(res2.status).toEqual(404); expect(res2.status).toEqual(404);
@ -211,7 +211,7 @@ describe('adding + updating successfilly', () => {
it('updating with new runner should return 200', async () => { it('updating with new runner should return 200', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, { const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id, "id": added_scan.id,
"track": added_track.id, "station": added_station.id,
"runner": added_runner2.id "runner": added_runner2.id
}, axios_config); }, axios_config);
expect(res2.status).toEqual(200); expect(res2.status).toEqual(200);
@ -220,7 +220,7 @@ describe('adding + updating successfilly', () => {
it('updating with new station should return 200', async () => { it('updating with new station should return 200', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, { const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id, "id": added_scan.id,
"track": added_track2.id, "station": added_station2.id,
"runner": added_runner.id "runner": added_runner.id
}, axios_config); }, axios_config);
expect(res2.status).toEqual(200); expect(res2.status).toEqual(200);
@ -229,7 +229,7 @@ describe('adding + updating successfilly', () => {
it('updating with valid=false should return 200', async () => { it('updating with valid=false should return 200', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, { const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id, "id": added_scan.id,
"track": added_track2.id, "station": added_station2.id,
"runner": added_runner.id, "runner": added_runner.id,
"valid": false "valid": false
}, axios_config); }, axios_config);