backend/src/models/Track.ts

53 lines
941 B
TypeScript

import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
IsString,
} from "class-validator";
import { ScanStation } from "./ScanStation";
import { TrackScan } from "./TrackScan";
/**
* Defines a track of given length.
*/
@Entity()
export class Track {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;;
/**
* The track's name.
*/
@Column()
@IsString()
@IsNotEmpty()
name: string;
/**
* The track's length/distance in meters.
*/
@Column()
@IsInt()
@IsPositive()
distance: number;
/**
* Used to link scan stations to track.
*/
@OneToMany(() => ScanStation, station => station.track)
stations: ScanStation[];
/**
* Used to link track scans to a track.
*/
@OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[];
}