backend/src/models/responses/ResponseScan.ts

65 lines
1.6 KiB
TypeScript

import { IsBoolean, IsInt, IsNotEmpty, IsPositive } from "class-validator";
import { Scan } from '../entities/Scan';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseRunner } from './ResponseRunner';
/**
* Defines the scan response.
*/
export class ResponseScan implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.SCAN;
/**
* The scans's id.
*/
@IsInt()
id: number;;
/**
* The scan's associated runner.
* This is important to link ran distances to runners.
*/
@IsNotEmpty()
runner: ResponseRunner;
/**
* Is the scan valid (for fraud reasons).
* The determination of validity will work differently for every child class.
*/
@IsBoolean()
valid: boolean = true;
/**
* The scans's length/distance in meters.
*/
@IsInt()
@IsPositive()
distance: number;
@IsInt()
@IsPositive()
created_at: number;
@IsInt()
@IsPositive()
updated_at: number;
/**
* Creates a ResponseScan object from a scan.
* @param scan The scan the response shall be build for.
*/
public constructor(scan: Scan) {
this.id = scan.id;
if (scan.runner) { this.runner = scan.runner.toResponse(); }
this.distance = scan.distance;
this.valid = scan.valid;
this.created_at = scan.created_at;
this.updated_at = scan.updated_at;
}
}