backend/src/models/entities/RunnerCard.ts

61 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-12-01 17:16:17 +00:00
import {
IsBoolean,
2020-12-03 16:26:54 +00:00
IsEAN,
2020-12-01 17:16:17 +00:00
IsInt,
IsNotEmpty,
IsOptional,
IsString
2020-12-01 17:16:17 +00:00
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
2020-12-01 17:16:17 +00:00
import { Runner } from "./Runner";
2020-12-02 14:40:25 +00:00
import { TrackScan } from "./TrackScan";
2020-12-01 17:16:17 +00:00
/**
* Defines the RunnerCard entity.
* A runnerCard is a physical representation for a runner.
* It can be associated with a runner to create scans via the scan station's.
2020-12-01 17:16:17 +00:00
*/
@Entity()
export class RunnerCard {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsInt()
id: number;
/**
* The card's currently associated runner.
* To increase reusability a card can be reassigned.
2020-12-01 17:16:17 +00:00
*/
@IsOptional()
@ManyToOne(() => Runner, runner => runner.cards, { nullable: true })
2020-12-01 17:16:17 +00:00
runner: Runner;
/**
* The card's code.
* This has to be able to being converted to something barcode compatible.
* Will get automaticlly generated (not implemented yet).
2020-12-01 17:16:17 +00:00
*/
@Column()
2020-12-03 16:26:54 +00:00
@IsEAN()
2020-12-01 17:16:17 +00:00
@IsString()
@IsNotEmpty()
code: string;
/**
* Is the card enabled (for fraud reasons)?
2020-12-02 17:05:18 +00:00
* Default: true
2020-12-01 17:16:17 +00:00
*/
@Column()
@IsBoolean()
2020-12-02 17:05:18 +00:00
enabled: boolean = true;
2020-12-02 14:40:25 +00:00
/**
* The card's associated scans.
* Used to link cards to track scans.
2020-12-02 14:40:25 +00:00
*/
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true })
2020-12-02 14:40:25 +00:00
scans: TrackScan[];
2020-12-01 17:16:17 +00:00
}