inspection data model
This commit is contained in:
parent
95d1113ff9
commit
3ff44f7370
9 changed files with 222 additions and 21 deletions
36
src/entity/unit/inspection/inspection.ts
Normal file
36
src/entity/unit/inspection/inspection.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { Column, ColumnType, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { inspectionPlan } from "./inspectionPlan";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||
import { Vehicle } from "../vehicle/vehicle";
|
||||
import { Equipment } from "../equipment/equipment";
|
||||
|
||||
@Entity()
|
||||
export class inspection {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column({ type: "text" })
|
||||
context: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
@Column({ type: getTypeByORM("date").type as ColumnType, nullable: true })
|
||||
finished?: Date;
|
||||
|
||||
@Column({ type: getTypeByORM("date").type as ColumnType, nullable: true })
|
||||
nextInspection?: Date;
|
||||
|
||||
@ManyToOne(() => inspectionPlan)
|
||||
inspectionPlan: inspectionPlan;
|
||||
|
||||
@ManyToOne(() => inspectionVersionedPlan)
|
||||
inspectionVersionedPlan: inspectionVersionedPlan;
|
||||
|
||||
@ManyToOne(() => Equipment)
|
||||
equipment: Equipment;
|
||||
|
||||
@ManyToOne(() => Vehicle)
|
||||
vehicle: Vehicle;
|
||||
}
|
42
src/entity/unit/inspection/inspectionPlan.ts
Normal file
42
src/entity/unit/inspection/inspectionPlan.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Equipment } from "../equipment/equipment";
|
||||
import { Vehicle } from "../vehicle/vehicle";
|
||||
import { PlanTimeDefinition } from "../../../viewmodel/admin/unit/inspectionPlan/inspectionPlan.models";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
|
||||
@Entity()
|
||||
export class inspectionPlan {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
inspectionInterval: PlanTimeDefinition;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
remindTime: PlanTimeDefinition;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column()
|
||||
equipmentId: string;
|
||||
|
||||
@Column()
|
||||
vehicleId: string;
|
||||
|
||||
@ManyToOne(() => Equipment)
|
||||
equipment: Equipment;
|
||||
|
||||
@ManyToOne(() => Vehicle)
|
||||
vehicle: Vehicle;
|
||||
|
||||
@OneToMany(() => inspectionVersionedPlan, (ivp) => ivp.inspectionPlan, {
|
||||
cascade: ["insert"],
|
||||
})
|
||||
versionedPlans: inspectionVersionedPlan[];
|
||||
|
||||
latestVersionedPlan?: inspectionVersionedPlan;
|
||||
}
|
39
src/entity/unit/inspection/inspectionPoint.ts
Normal file
39
src/entity/unit/inspection/inspectionPoint.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { InspectionPointEnum } from "../../../enums/inspectionEnum";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
|
||||
@Entity()
|
||||
export class inspectionPoint {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "text" })
|
||||
description: string;
|
||||
|
||||
@Column({
|
||||
type: "varchar",
|
||||
length: 255,
|
||||
transformer: {
|
||||
to(value: InspectionPointEnum) {
|
||||
return value.toString();
|
||||
},
|
||||
from(value: string) {
|
||||
return InspectionPointEnum[value as keyof typeof InspectionPointEnum];
|
||||
},
|
||||
},
|
||||
})
|
||||
type: InspectionPointEnum;
|
||||
|
||||
@Column({ type: "int", default: 0 })
|
||||
min: number;
|
||||
|
||||
@ManyToOne(() => inspectionVersionedPlan, {
|
||||
nullable: false,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
versionedPlan: inspectionVersionedPlan;
|
||||
}
|
19
src/entity/unit/inspection/inspectionPointResult.ts
Normal file
19
src/entity/unit/inspection/inspectionPointResult.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { inspection } from "./inspection";
|
||||
import { inspectionPoint } from "./inspectionPoint";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
|
||||
@Entity()
|
||||
export class inspectionPointResult {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column({ type: "text" })
|
||||
value: string;
|
||||
|
||||
@ManyToOne(() => inspection)
|
||||
inspection: inspection;
|
||||
|
||||
@ManyToOne(() => inspectionPoint)
|
||||
inspectionPoint: inspectionPoint;
|
||||
}
|
35
src/entity/unit/inspection/inspectionVersionedPlan.ts
Normal file
35
src/entity/unit/inspection/inspectionVersionedPlan.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, Unique } from "typeorm";
|
||||
import { Equipment } from "../equipment/equipment";
|
||||
import { Vehicle } from "../vehicle/vehicle";
|
||||
import { PlanTimeDefinition } from "../../../viewmodel/admin/unit/inspectionPlan/inspectionPlan.models";
|
||||
import { inspectionPlan } from "./inspectionPlan";
|
||||
import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||
import { inspectionPoint } from "./inspectionPoint";
|
||||
|
||||
@Entity()
|
||||
@Unique("unique_version", ["version", "inspectionPlanId"])
|
||||
export class inspectionVersionedPlan {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id: string;
|
||||
|
||||
@Column({ type: "int", default: 0 })
|
||||
version: number;
|
||||
|
||||
@CreateDateColumn()
|
||||
created: Date;
|
||||
|
||||
@Column()
|
||||
inspectionPlanId: string;
|
||||
|
||||
@ManyToOne(() => inspectionPlan, {
|
||||
nullable: false,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
inspectionPlan: inspectionPlan;
|
||||
|
||||
@OneToMany(() => inspectionPoint, (ip) => ip.versionedPlan, {
|
||||
cascade: ["insert"],
|
||||
})
|
||||
inspectionPoints: inspectionPoint[];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue