39 lines
1 KiB
TypeScript
39 lines
1 KiB
TypeScript
|
import { Column, ColumnType, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||
|
import { getTypeByORM } from "../../../migrations/ormHelper";
|
||
|
import { VehicleType } from "./vehicleType";
|
||
|
import { DamageReport } from "../damageReport";
|
||
|
|
||
|
@Entity()
|
||
|
export class Vehicle {
|
||
|
@PrimaryGeneratedColumn("uuid")
|
||
|
id: string;
|
||
|
|
||
|
@Column({ type: "varchar", length: 255, nullable: true, unique: true })
|
||
|
code?: string;
|
||
|
|
||
|
@Column({ type: "varchar", length: 255 })
|
||
|
name: string;
|
||
|
|
||
|
@Column({ type: "varchar", length: 255 })
|
||
|
location: string;
|
||
|
|
||
|
@Column({ type: getTypeByORM("datetime").type as ColumnType })
|
||
|
commissioned: Date;
|
||
|
|
||
|
@Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true })
|
||
|
decommissioned?: Date;
|
||
|
|
||
|
@Column()
|
||
|
vehicleTypeId: string;
|
||
|
|
||
|
@ManyToOne(() => VehicleType, {
|
||
|
nullable: false,
|
||
|
onDelete: "RESTRICT",
|
||
|
onUpdate: "RESTRICT",
|
||
|
})
|
||
|
vehicleType: VehicleType;
|
||
|
|
||
|
@OneToMany(() => DamageReport, (d) => d.vehicle, { cascade: ["insert"] })
|
||
|
reports: DamageReport[];
|
||
|
}
|