Features for the new selfservice feature/151-selfservice_scans_mails #152
@ -44,6 +44,7 @@ export class CreateTrackScan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newScan.timestamp = Math.round(new Date().getTime() / 1000);
|
newScan.timestamp = Math.round(new Date().getTime() / 1000);
|
||||||
|
newScan.lapTime = await this.getLaptime(newScan)
|
||||||
newScan.valid = await this.validateScan(newScan);
|
newScan.valid = await this.validateScan(newScan);
|
||||||
|
|
||||||
return newScan;
|
return newScan;
|
||||||
@ -65,15 +66,15 @@ export class CreateTrackScan {
|
|||||||
return station;
|
return station;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async validateScan(scan: TrackScan): Promise<boolean> {
|
public validateScan(scan: TrackScan): boolean {
|
||||||
|
return (scan.lapTime > scan.track.minimumLapTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getLaptime(scan: TrackScan): Promise<number> {
|
||||||
const scans = await getConnection().getRepository(TrackScan).find({ where: { runner: scan.runner, valid: true }, relations: ["track"] });
|
const scans = await getConnection().getRepository(TrackScan).find({ where: { runner: scan.runner, valid: true }, relations: ["track"] });
|
||||||
if (scans.length == 0) { return true; }
|
if (scans.length == 0) { return 0; }
|
||||||
|
|
||||||
const newestScan = scans[scans.length - 1];
|
const newestScan = scans[scans.length - 1];
|
||||||
if ((scan.timestamp - newestScan.timestamp) > scan.track.minimumLapTime) {
|
return (scan.timestamp - newestScan.timestamp);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ import {
|
|||||||
IsInt,
|
IsInt,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
|
|
||||||
|
IsNumber,
|
||||||
|
|
||||||
IsPositive
|
IsPositive
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
import { ChildEntity, Column, ManyToOne } from "typeorm";
|
import { ChildEntity, Column, ManyToOne } from "typeorm";
|
||||||
@ -59,6 +61,14 @@ export class TrackScan extends Scan {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scan's lap time.
|
||||||
|
* This simply get's calculated from the last lap time;
|
||||||
|
*/
|
||||||
|
@Column()
|
||||||
|
@IsNumber()
|
||||||
|
lapTime: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns this entity into it's response class.
|
* Turns this entity into it's response class.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user