Fixed runner scan validation bug

ref #67
This commit is contained in:
Nicolai Ort 2021-01-07 16:59:57 +01:00
parent e67d1c5697
commit edac1a224c
3 changed files with 2 additions and 3 deletions

View File

@ -53,7 +53,6 @@ export class ScanController {
async post(@Body({ validate: true }) createScan: CreateScan) { async post(@Body({ validate: true }) createScan: CreateScan) {
let scan = await createScan.toScan(); let scan = await createScan.toScan();
scan = await this.scanRepository.save(scan); scan = await this.scanRepository.save(scan);
console.log(scan);
return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner'] })).toResponse(); return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner'] })).toResponse();
} }

View File

@ -48,7 +48,7 @@ export class Runner extends Participant {
* This is implemented here to avoid duplicate code in other files. * This is implemented here to avoid duplicate code in other files.
*/ */
public get validScans(): Scan[] { public get validScans(): Scan[] {
return this.scans.filter(scan => { scan.valid === true }); return this.scans.filter(scan => scan.valid == true);
} }
/** /**

View File

@ -30,7 +30,7 @@ export class ResponseRunner extends ResponseParticipant {
public constructor(runner: Runner) { public constructor(runner: Runner) {
super(runner); super(runner);
if (!runner.scans) { this.distance = 0 } if (!runner.scans) { this.distance = 0 }
else { this.distance = runner.scans.filter(scan => { scan.valid === true }).reduce((sum, current) => sum + current.distance, 0); } else { this.distance = runner.validScans.reduce((sum, current) => sum + current.distance, 0); }
this.group = runner.group; this.group = runner.group;
} }
} }