Compare commits
5 commits
baa3b2cc8c
...
117ced38ab
Author | SHA1 | Date | |
---|---|---|---|
117ced38ab | |||
fcbfe560c3 | |||
e404989a28 | |||
2433120e26 | |||
8c81c8f336 |
47 changed files with 1058 additions and 47 deletions
|
@ -23,33 +23,36 @@ export class damageReport {
|
|||
@Column({ type: "varchar", length: 255 })
|
||||
reportedBy: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
equipmentId: string;
|
||||
@Column({ type: "int", default: 0 })
|
||||
imageCount: number;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
vehicleId: string;
|
||||
equipmentId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
wearableId: string;
|
||||
vehicleId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
wearableId?: string;
|
||||
|
||||
@ManyToOne(() => equipment, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
equipment: equipment;
|
||||
equipment?: equipment;
|
||||
|
||||
@ManyToOne(() => vehicle, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
vehicle: vehicle;
|
||||
vehicle?: vehicle;
|
||||
|
||||
@ManyToOne(() => wearable, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
wearable: wearable;
|
||||
wearable?: wearable;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Column, ColumnType, Entity, ManyToOne, OneToMany, PrimaryGeneratedColum
|
|||
import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||
import { equipmentType } from "./equipmentType";
|
||||
import { damageReport } from "../damageReport";
|
||||
import { inspection } from "../inspection/inspection";
|
||||
|
||||
@Entity()
|
||||
export class equipment {
|
||||
|
@ -35,4 +36,7 @@ export class equipment {
|
|||
|
||||
@OneToMany(() => damageReport, (d) => d.equipment, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.equipment)
|
||||
inspections: inspection[];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { equipment } from "./equipment";
|
||||
import { inspectionPlan } from "../inspection/inspectionPlan";
|
||||
|
||||
@Entity()
|
||||
export class equipmentType {
|
||||
|
@ -15,5 +16,6 @@ export class equipmentType {
|
|||
@OneToMany(() => equipment, (e) => e.equipmentType, { cascade: ["insert"] })
|
||||
equipment: equipment[];
|
||||
|
||||
inspectionPlans: Array<any>;
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.equipment)
|
||||
inspectionPlans: inspectionPlan[];
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { Column, ColumnType, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, ColumnType, CreateDateColumn, Entity, ManyToOne, OneToMany, 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";
|
||||
import { inspectionPointResult } from "./inspectionPointResult";
|
||||
|
||||
@Entity()
|
||||
export class inspection {
|
||||
|
@ -22,6 +23,18 @@ export class inspection {
|
|||
@Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null })
|
||||
nextInspection?: Date;
|
||||
|
||||
@Column()
|
||||
inspectionPlanId: string;
|
||||
|
||||
@Column()
|
||||
inspectionVersionedPlanId: string;
|
||||
|
||||
@Column()
|
||||
equipmentId?: string;
|
||||
|
||||
@Column()
|
||||
vehicleId?: string;
|
||||
|
||||
@ManyToOne(() => inspectionPlan, {
|
||||
nullable: false,
|
||||
onDelete: "RESTRICT",
|
||||
|
@ -49,4 +62,7 @@ export class inspection {
|
|||
onUpdate: "RESTRICT",
|
||||
})
|
||||
vehicle: vehicle;
|
||||
|
||||
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection)
|
||||
pointResults: inspectionPointResult[];
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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 { PlanTimeDefinition } from "../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
|
||||
@Entity()
|
||||
|
@ -22,16 +22,24 @@ export class inspectionPlan {
|
|||
createdAt: Date;
|
||||
|
||||
@Column()
|
||||
equipmentId: string;
|
||||
equipmentId?: string;
|
||||
|
||||
@Column()
|
||||
vehicleId: string;
|
||||
vehicleId?: string;
|
||||
|
||||
@ManyToOne(() => equipment)
|
||||
equipment: equipment;
|
||||
@ManyToOne(() => equipment, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
equipment?: equipment;
|
||||
|
||||
@ManyToOne(() => vehicle)
|
||||
vehicle: vehicle;
|
||||
@ManyToOne(() => vehicle, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
vehicle?: vehicle;
|
||||
|
||||
@OneToMany(() => inspectionVersionedPlan, (ivp) => ivp.inspectionPlan, {
|
||||
cascade: ["insert"],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
|
||||
import { InspectionPointEnum } from "../../../enums/inspectionEnum";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
|
||||
|
@ -28,10 +28,13 @@ export class inspectionPoint {
|
|||
type: InspectionPointEnum;
|
||||
|
||||
@Column({ type: "int", nullable: true, default: null })
|
||||
min: number;
|
||||
min?: number;
|
||||
|
||||
@Column({ type: "int", nullable: true, default: null })
|
||||
max: number;
|
||||
max?: number;
|
||||
|
||||
@Column({ type: "int", default: 0 })
|
||||
sort: number;
|
||||
|
||||
@Column()
|
||||
versionedPlanId: string;
|
||||
|
|
|
@ -10,6 +10,12 @@ export class inspectionPointResult {
|
|||
@Column({ type: "text" })
|
||||
value: string;
|
||||
|
||||
@Column()
|
||||
inspectionId: string;
|
||||
|
||||
@Column()
|
||||
inspectionPointId: string;
|
||||
|
||||
@ManyToOne(() => inspection, {
|
||||
nullable: false,
|
||||
onDelete: "CASCADE",
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Column, ColumnType, Entity, ManyToOne, OneToMany, PrimaryGeneratedColum
|
|||
import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||
import { vehicleType } from "./vehicleType";
|
||||
import { damageReport } from "../damageReport";
|
||||
import { inspection } from "../inspection/inspection";
|
||||
|
||||
@Entity()
|
||||
export class vehicle {
|
||||
|
@ -35,4 +36,7 @@ export class vehicle {
|
|||
|
||||
@OneToMany(() => damageReport, (d) => d.vehicle, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.vehicle)
|
||||
inspections: inspection[];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { vehicle } from "./vehicle";
|
||||
import { inspectionPlan } from "../inspection/inspectionPlan";
|
||||
|
||||
@Entity()
|
||||
export class vehicleType {
|
||||
|
@ -15,5 +16,6 @@ export class vehicleType {
|
|||
@OneToMany(() => vehicle, (e) => e.vehicleType, { cascade: ["insert"] })
|
||||
vehicle: vehicle[];
|
||||
|
||||
inspectionPlans: Array<any>;
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.vehicle)
|
||||
inspectionPlans: inspectionPlan[];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { getTypeByORM } from "../../../migrations/ormHelper";
|
|||
import { wearableType } from "./wearableType";
|
||||
import { damageReport } from "../damageReport";
|
||||
import { member } from "../../club/member/member";
|
||||
import { inspection } from "../inspection/inspection";
|
||||
|
||||
@Entity()
|
||||
export class wearable {
|
||||
|
@ -28,7 +29,7 @@ export class wearable {
|
|||
wearableTypeId: string;
|
||||
|
||||
@Column()
|
||||
wearerId: string;
|
||||
wearerId?: string;
|
||||
|
||||
@ManyToOne(() => wearableType, {
|
||||
nullable: false,
|
||||
|
@ -38,11 +39,11 @@ export class wearable {
|
|||
wearableType: wearableType;
|
||||
|
||||
@ManyToOne(() => member, {
|
||||
nullable: false,
|
||||
nullable: true,
|
||||
onDelete: "SET NULL",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
wearer: member;
|
||||
wearer?: member;
|
||||
|
||||
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
|
55
src/factory/admin/unit/damageReport.ts
Normal file
55
src/factory/admin/unit/damageReport.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { damageReport } from "../../../entity/unit/damageReport";
|
||||
import { DamageReportAssigned, DamageReportViewModel } from "../../../viewmodel/admin/unit/damageReport.models";
|
||||
import EquipmentFactory from "./equipment/equipment";
|
||||
import VehicleFactory from "./vehicle/vehicle";
|
||||
import WearableFactory from "./wearable/wearable";
|
||||
|
||||
export default abstract class DamageReportFactory {
|
||||
/**
|
||||
* @description map record to damageReport
|
||||
* @param {damageReport} record
|
||||
* @returns {DamageReportViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: damageReport): DamageReportViewModel {
|
||||
let assigned: DamageReportAssigned;
|
||||
if (record?.equipmentId) {
|
||||
assigned = {
|
||||
relatedId: record.equipmentId,
|
||||
assigned: "equipment",
|
||||
related: EquipmentFactory.mapToSingle(record.equipment),
|
||||
};
|
||||
} else if (record?.vehicleId) {
|
||||
assigned = {
|
||||
relatedId: record.vehicleId,
|
||||
assigned: "vehicle",
|
||||
related: VehicleFactory.mapToSingle(record.vehicle),
|
||||
};
|
||||
} else {
|
||||
assigned = {
|
||||
relatedId: record.wearableId,
|
||||
assigned: "wearable",
|
||||
related: WearableFactory.mapToSingle(record.wearable),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
reported: record.reportedAt,
|
||||
status: record.status,
|
||||
done: record.done,
|
||||
description: record.description,
|
||||
imageCount: record.imageCount,
|
||||
reportedBy: record?.reportedBy,
|
||||
...assigned,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to damageReport
|
||||
* @param {Array<damageReport>} records
|
||||
* @returns {Array<DamageReportViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<damageReport>): Array<DamageReportViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
32
src/factory/admin/unit/equipment/equipment.ts
Normal file
32
src/factory/admin/unit/equipment/equipment.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { equipment } from "../../../../entity/unit/equipment/equipment";
|
||||
import { EquipmentViewModel } from "../../../../viewmodel/admin/unit/equipment/equipment.models";
|
||||
import EquipmentTypeFactory from "./equipmentType";
|
||||
|
||||
export default abstract class EquipmentFactory {
|
||||
/**
|
||||
* @description map record to equipment
|
||||
* @param {equipment} record
|
||||
* @returns {EquipmentViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: equipment): EquipmentViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
code: record?.code,
|
||||
name: record.name,
|
||||
location: record.location,
|
||||
commissioned: record.commissioned,
|
||||
decommissioned: record?.decommissioned,
|
||||
equipmentTypeId: record?.equipmentTypeId,
|
||||
equipmentType: record?.equipmentType ? EquipmentTypeFactory.mapToSingle(record.equipmentType) : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to equipment
|
||||
* @param {Array<equipment>} records
|
||||
* @returns {Array<EquipmentViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<equipment>): Array<EquipmentViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
26
src/factory/admin/unit/equipment/equipmentType.ts
Normal file
26
src/factory/admin/unit/equipment/equipmentType.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { equipmentType } from "../../../../entity/unit/equipment/equipmentType";
|
||||
import { EquipmentTypeViewModel } from "../../../../viewmodel/admin/unit/equipment/equipmentType.models";
|
||||
|
||||
export default abstract class EquipmentTypeFactory {
|
||||
/**
|
||||
* @description map record to equipmentType
|
||||
* @param {equipmentType} record
|
||||
* @returns {EquipmentTypeViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: equipmentType): EquipmentTypeViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
type: record.type,
|
||||
description: record.description,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to equipmentType
|
||||
* @param {Array<equipmentType>} records
|
||||
* @returns {Array<EquipmentTypeViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<equipmentType>): Array<EquipmentTypeViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
50
src/factory/admin/unit/inspection/inspection.ts
Normal file
50
src/factory/admin/unit/inspection/inspection.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { inspection } from "../../../../entity/unit/inspection/inspection";
|
||||
import { InspectionViewModel } from "../../../../viewmodel/admin/unit/inspection/inspection.models";
|
||||
import EquipmentFactory from "../equipment/equipment";
|
||||
import VehicleFactory from "../vehicle/vehicle";
|
||||
import InspectionPlanFactory from "./inspectionPlan";
|
||||
import InspectionPointResultFactory from "./inspectionPointResult";
|
||||
import InspectionVersionedPlanFactory from "./inspectionVersionedPlan";
|
||||
|
||||
export default abstract class InspectionFactory {
|
||||
/**
|
||||
* @description map record to inspection
|
||||
* @param {inspection} record
|
||||
* @returns {InspectionViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: inspection): InspectionViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
inspectionPlanId: record.inspectionPlanId,
|
||||
inspectionPlan: InspectionPlanFactory.mapToSingle(record.inspectionPlan),
|
||||
inspectionVersionedPlanId: record.inspectionVersionedPlanId,
|
||||
inspectionVersionedPlan: InspectionVersionedPlanFactory.mapToSingle(record.inspectionVersionedPlan),
|
||||
context: record.context,
|
||||
created: record.createdAt,
|
||||
finished: record?.finishedAt,
|
||||
isOpen: record?.finishedAt == undefined,
|
||||
nextInspection: record?.nextInspection,
|
||||
checks: InspectionPointResultFactory.mapToBase(record.pointResults),
|
||||
...(record.equipmentId
|
||||
? {
|
||||
relatedId: record.equipmentId,
|
||||
assigned: "equipment",
|
||||
related: EquipmentFactory.mapToSingle(record.equipment),
|
||||
}
|
||||
: {
|
||||
relatedId: record.vehicleId,
|
||||
assigned: "vehicle",
|
||||
related: VehicleFactory.mapToSingle(record.vehicle),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to inspection
|
||||
* @param {Array<inspection>} records
|
||||
* @returns {Array<InspectionViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<inspection>): Array<InspectionViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
44
src/factory/admin/unit/inspection/inspectionPlan.ts
Normal file
44
src/factory/admin/unit/inspection/inspectionPlan.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { inspectionPlan } from "../../../../entity/unit/inspection/inspectionPlan";
|
||||
import { InspectionPlanViewModel } from "../../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
||||
import EquipmentFactory from "../equipment/equipment";
|
||||
import VehicleFactory from "../vehicle/vehicle";
|
||||
import InspectionPointFactory from "./inspectionPoint";
|
||||
|
||||
export default abstract class InspectionPlanFactory {
|
||||
/**
|
||||
* @description map record to inspectionPlan
|
||||
* @param {inspectionPlan} record
|
||||
* @returns {InspectionPlanViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: inspectionPlan): InspectionPlanViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
title: record.title,
|
||||
inspectionInterval: record.inspectionInterval,
|
||||
remindTime: record.remindTime,
|
||||
version: record.latestVersionedPlan.version,
|
||||
created: record.createdAt,
|
||||
inspectionPoints: InspectionPointFactory.mapToBase(record.latestVersionedPlan.inspectionPoints),
|
||||
...(record.equipmentId
|
||||
? {
|
||||
relatedId: record.equipmentId,
|
||||
assigned: "equipment",
|
||||
related: EquipmentFactory.mapToSingle(record.equipment),
|
||||
}
|
||||
: {
|
||||
relatedId: record.vehicleId,
|
||||
assigned: "vehicle",
|
||||
related: VehicleFactory.mapToSingle(record.vehicle),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to inspectionPlan
|
||||
* @param {Array<inspectionPlan>} records
|
||||
* @returns {Array<InspectionPlanViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<inspectionPlan>): Array<InspectionPlanViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
30
src/factory/admin/unit/inspection/inspectionPoint.ts
Normal file
30
src/factory/admin/unit/inspection/inspectionPoint.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { inspectionPoint } from "../../../../entity/unit/inspection/inspectionPoint";
|
||||
import { InspectionPointViewModel } from "../../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
||||
|
||||
export default abstract class InspectionPointFactory {
|
||||
/**
|
||||
* @description map record to inspectionPoint
|
||||
* @param {inspectionPoint} record
|
||||
* @returns {InspectionPointViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: inspectionPoint): InspectionPointViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
type: record.type,
|
||||
sort: record.sort,
|
||||
min: record?.min,
|
||||
max: record?.max,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to inspectionPoint
|
||||
* @param {Array<inspectionPoint>} records
|
||||
* @returns {Array<InspectionPointViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<inspectionPoint>): Array<InspectionPointViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
29
src/factory/admin/unit/inspection/inspectionPointResult.ts
Normal file
29
src/factory/admin/unit/inspection/inspectionPointResult.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { inspectionPointResult } from "../../../../entity/unit/inspection/inspectionPointResult";
|
||||
import { InspectionPointResultViewModel } from "../../../../viewmodel/admin/unit/inspection/inspection.models";
|
||||
import InspectionPointFactory from "./inspectionPoint";
|
||||
|
||||
export default abstract class InspectionPointResultFactory {
|
||||
/**
|
||||
* @description map record to inspectionPointResult
|
||||
* @param {inspectionPointResult} record
|
||||
* @returns {InspectionPointResultViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: inspectionPointResult): InspectionPointResultViewModel {
|
||||
return {
|
||||
inspectionId: record.inspectionId,
|
||||
inspectionVersionedPlanId: record.inspection.inspectionVersionedPlanId,
|
||||
inspectionPointId: record.inspectionPointId,
|
||||
inspectionPoint: InspectionPointFactory.mapToSingle(record.inspectionPoint),
|
||||
value: record.value,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to inspectionPointResult
|
||||
* @param {Array<inspectionPointResult>} records
|
||||
* @returns {Array<InspectionPointResultViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<inspectionPointResult>): Array<InspectionPointResultViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
28
src/factory/admin/unit/inspection/inspectionVersionedPlan.ts
Normal file
28
src/factory/admin/unit/inspection/inspectionVersionedPlan.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { inspectionVersionedPlan } from "../../../../entity/unit/inspection/inspectionVersionedPlan";
|
||||
import { InspectionVersionedPlanViewModel } from "../../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
||||
import InspectionPointFactory from "./inspectionPoint";
|
||||
|
||||
export default abstract class InspectionVersionedPlanFactory {
|
||||
/**
|
||||
* @description map record to inspectionVersionedPlan
|
||||
* @param {inspectionVersionedPlan} record
|
||||
* @returns {InspectionVersionedPlanViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: inspectionVersionedPlan): InspectionVersionedPlanViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
version: record.version,
|
||||
created: record.createdAt,
|
||||
inspectionPoints: InspectionPointFactory.mapToBase(record.inspectionPoints),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to inspectionVersionedPlan
|
||||
* @param {Array<inspectionVersionedPlan>} records
|
||||
* @returns {Array<InspectionVersionedPlanViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<inspectionVersionedPlan>): Array<InspectionVersionedPlanViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
32
src/factory/admin/unit/vehicle/vehicle.ts
Normal file
32
src/factory/admin/unit/vehicle/vehicle.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { vehicle } from "../../../../entity/unit/vehicle/vehicle";
|
||||
import { VehicleViewModel } from "../../../../viewmodel/admin/unit/vehicle/vehicle.models";
|
||||
import VehicleTypeFactory from "./vehicleType";
|
||||
|
||||
export default abstract class VehicleFactory {
|
||||
/**
|
||||
* @description map record to vehicle
|
||||
* @param {vehicle} record
|
||||
* @returns {VehicleViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: vehicle): VehicleViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
code: record?.code,
|
||||
name: record.name,
|
||||
location: record.location,
|
||||
commissioned: record.commissioned,
|
||||
decommissioned: record?.decommissioned,
|
||||
vehicleTypeId: record?.vehicleTypeId,
|
||||
vehicleType: record?.vehicleType ? VehicleTypeFactory.mapToSingle(record.vehicleType) : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to vehicle
|
||||
* @param {Array<vehicle>} records
|
||||
* @returns {Array<VehicleViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<vehicle>): Array<VehicleViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
26
src/factory/admin/unit/vehicle/vehicleType.ts
Normal file
26
src/factory/admin/unit/vehicle/vehicleType.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { vehicleType } from "../../../../entity/unit/vehicle/vehicleType";
|
||||
import { VehicleTypeViewModel } from "../../../../viewmodel/admin/unit/vehicle/vehicleType.models";
|
||||
|
||||
export default abstract class VehicleTypeFactory {
|
||||
/**
|
||||
* @description map record to vehicleType
|
||||
* @param {vehicleType} record
|
||||
* @returns {VehicleTypeViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: vehicleType): VehicleTypeViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
type: record.type,
|
||||
description: record.description,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to vehicleType
|
||||
* @param {Array<vehicleType>} records
|
||||
* @returns {Array<VehicleTypeViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<vehicleType>): Array<VehicleTypeViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
35
src/factory/admin/unit/wearable/wearable.ts
Normal file
35
src/factory/admin/unit/wearable/wearable.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { wearable } from "../../../../entity/unit/wearable/wearable";
|
||||
import { WearableViewModel } from "../../../../viewmodel/admin/unit/wearable/wearable.models";
|
||||
import MemberFactory from "../../club/member/member";
|
||||
import WearableTypeFactory from "./wearableType";
|
||||
|
||||
export default abstract class WearableFactory {
|
||||
/**
|
||||
* @description map record to wearable
|
||||
* @param {wearable} record
|
||||
* @returns {WearableViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: wearable): WearableViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
code: record?.code,
|
||||
name: record.name,
|
||||
location: record.location,
|
||||
commissioned: record.commissioned,
|
||||
decommissioned: record?.decommissioned,
|
||||
wearableTypeId: record?.wearableTypeId,
|
||||
wearableType: record?.wearableType ? WearableTypeFactory.mapToSingle(record.wearableType) : null,
|
||||
wearerId: record?.wearerId,
|
||||
wearer: record?.wearer ? MemberFactory.mapToSingle(record.wearer) : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to wearable
|
||||
* @param {Array<wearable>} records
|
||||
* @returns {Array<WearableViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<wearable>): Array<WearableViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
26
src/factory/admin/unit/wearable/wearableType.ts
Normal file
26
src/factory/admin/unit/wearable/wearableType.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { wearableType } from "../../../../entity/unit/wearable/wearableType";
|
||||
import { WearableTypeViewModel } from "../../../../viewmodel/admin/unit/wearable/wearableType.models";
|
||||
|
||||
export default abstract class WearableTypeFactory {
|
||||
/**
|
||||
* @description map record to wearableType
|
||||
* @param {wearableType} record
|
||||
* @returns {WearableTypeViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: wearableType): WearableTypeViewModel {
|
||||
return {
|
||||
id: record.id,
|
||||
type: record.type,
|
||||
description: record.description,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description map records to wearableType
|
||||
* @param {Array<wearableType>} records
|
||||
* @returns {Array<WearableTypeViewModel>}
|
||||
*/
|
||||
public static mapToBase(records: Array<wearableType>): Array<WearableTypeViewModel> {
|
||||
return records.map((r) => this.mapToSingle(r));
|
||||
}
|
||||
}
|
|
@ -64,6 +64,7 @@ export const inspection_point_table = new Table({
|
|||
{ name: "type", ...getTypeByORM("varchar") },
|
||||
{ name: "min", ...getTypeByORM("int", true), default: getDefaultByORM("null") },
|
||||
{ name: "max", ...getTypeByORM("int", true), default: getDefaultByORM("null") },
|
||||
{ name: "sort", ...getTypeByORM("int"), default: getDefaultByORM("number", 0) },
|
||||
{ name: "versionedPlanId", ...getTypeByORM("uuid") },
|
||||
],
|
||||
foreignKeys: [
|
||||
|
|
44
src/service/unit/damageReport.ts
Normal file
44
src/service/unit/damageReport.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { dataSource } from "../../data-source";
|
||||
import { damageReport } from "../../entity/unit/damageReport";
|
||||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class DamageReportService {
|
||||
/**
|
||||
* @description get all damageReports
|
||||
* @returns {Promise<Array<damageReport>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<damageReport>> {
|
||||
return await dataSource
|
||||
.getRepository(damageReport)
|
||||
.createQueryBuilder("damageReport")
|
||||
.leftJoinAndSelect("damageReport.equipment", "equipment")
|
||||
.leftJoinAndSelect("damageReport.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("damageReport.wearable", "wearable")
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "damageReport", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get damageReport by id
|
||||
* @returns {Promise<damageReport>}
|
||||
*/
|
||||
static async getById(id: string): Promise<damageReport> {
|
||||
return await dataSource
|
||||
.getRepository(damageReport)
|
||||
.createQueryBuilder("damageReport")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "damageReport", err);
|
||||
});
|
||||
}
|
||||
}
|
43
src/service/unit/equipment/equipmentService.ts
Normal file
43
src/service/unit/equipment/equipmentService.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { equipment } from "../../../entity/unit/equipment/equipment";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class EquipmentService {
|
||||
/**
|
||||
* @description get all equipment
|
||||
* @returns {Promise<Array<equipment>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipment>> {
|
||||
return await dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "equipment", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get equipment by id
|
||||
* @returns {Promise<equipment>}
|
||||
*/
|
||||
static async getById(id: string): Promise<equipment> {
|
||||
return await dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "equipment", err);
|
||||
});
|
||||
}
|
||||
}
|
41
src/service/unit/equipment/equipmentTypeService.ts
Normal file
41
src/service/unit/equipment/equipmentTypeService.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { equipmentType } from "../../../entity/unit/equipment/equipmentType";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class EquipmentTypeService {
|
||||
/**
|
||||
* @description get all equipmentTypes
|
||||
* @returns {Promise<Array<equipmentType>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipmentType>> {
|
||||
return await dataSource
|
||||
.getRepository(equipmentType)
|
||||
.createQueryBuilder("equipmentType")
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "equipmentType", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get equipmentType by id
|
||||
* @returns {Promise<equipmentType>}
|
||||
*/
|
||||
static async getById(id: string): Promise<equipmentType> {
|
||||
return await dataSource
|
||||
.getRepository(equipmentType)
|
||||
.createQueryBuilder("equipmentType")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "equipmentType", err);
|
||||
});
|
||||
}
|
||||
}
|
67
src/service/unit/inspection/inspectionPlanService.ts
Normal file
67
src/service/unit/inspection/inspectionPlanService.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { inspectionPlan } from "../../../entity/unit/inspection/inspectionPlan";
|
||||
import { DB_TYPE } from "../../../env.defaults";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionPlanService {
|
||||
/**
|
||||
* @description get all inspectionPlans for related
|
||||
* @returns {Promise<Array<inspectionPlan>>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string }
|
||||
): Promise<Array<inspectionPlan>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPlan)
|
||||
.createQueryBuilder("inspectionPlan")
|
||||
.leftJoinAndMapOne(
|
||||
"inspectionPlan.latestVersionedPlan",
|
||||
"inspectionPlan.versionedPlans",
|
||||
"latestVersionedPlan",
|
||||
DB_TYPE == "postgres"
|
||||
? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."start") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")'
|
||||
: "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.start) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||
.where(where)
|
||||
.orderBy("title", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPlan", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get inspectionPlan by id
|
||||
* @returns {Promise<inspectionPlan>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspectionPlan> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPlan)
|
||||
.createQueryBuilder("inspectionPlan")
|
||||
.leftJoinAndMapOne(
|
||||
"inspectionPlan.latestVersionedPlan",
|
||||
"inspectionPlan.versionedPlans",
|
||||
"latestVersionedPlan",
|
||||
DB_TYPE == "postgres"
|
||||
? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."start") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")'
|
||||
: "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.start) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPlan", err);
|
||||
});
|
||||
}
|
||||
}
|
43
src/service/unit/inspection/inspectionPointResultService.ts
Normal file
43
src/service/unit/inspection/inspectionPointResultService.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { inspectionPointResult } from "../../../entity/unit/inspection/inspectionPointResult";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionPointResultService {
|
||||
/**
|
||||
* @description get all inspectionPointResults
|
||||
* @returns {Promise<Array<inspectionPointResult>>}
|
||||
*/
|
||||
static async getAllForInspection(inspectionId: string): Promise<Array<inspectionPointResult>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPointResult)
|
||||
.createQueryBuilder("inspectionPointResult")
|
||||
.leftJoinAndSelect("inspectionPointResult.inspectionPoint", "inspectionPoint")
|
||||
.where({ inspectionId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPointResult", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get inspectionPointResult by id
|
||||
* @returns {Promise<inspectionPointResult>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspectionPointResult> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPointResult)
|
||||
.createQueryBuilder("inspectionPointResult")
|
||||
.leftJoinAndSelect("inspectionPointResult.inspectionPoint", "inspectionPoint")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPointResult", err);
|
||||
});
|
||||
}
|
||||
}
|
42
src/service/unit/inspection/inspectionPointService.ts
Normal file
42
src/service/unit/inspection/inspectionPointService.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { inspectionPoint } from "../../../entity/unit/inspection/inspectionPoint";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionPointService {
|
||||
/**
|
||||
* @description get all inspectionPoints
|
||||
* @returns {Promise<Array<inspectionPoint>>}
|
||||
*/
|
||||
static async getAllForVersionedPlan(versionedPlanId: string): Promise<Array<inspectionPoint>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPoint)
|
||||
.createQueryBuilder("inspectionPoint")
|
||||
.where({ versionedPlanId })
|
||||
.orderBy("sort", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPoint", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get inspectionPoint by id
|
||||
* @returns {Promise<inspectionPoint>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspectionPoint> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPoint)
|
||||
.createQueryBuilder("inspectionPoint")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPoint", err);
|
||||
});
|
||||
}
|
||||
}
|
56
src/service/unit/inspection/inspectionService.ts
Normal file
56
src/service/unit/inspection/inspectionService.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { inspection } from "../../../entity/unit/inspection/inspection";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionService {
|
||||
/**
|
||||
* @description get all inspections for related
|
||||
* @returns {Promise<Array<inspection>>}
|
||||
*/
|
||||
static async getAllForRelated(where: { equipmentId: string } | { vehicleId: string }): Promise<Array<inspection>> {
|
||||
return await dataSource
|
||||
.getRepository(inspection)
|
||||
.createQueryBuilder("inspection")
|
||||
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
||||
.leftJoinAndSelect("inspection.inspectionVersionedPlan", "inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||
.where(where)
|
||||
.orderBy("createdAt", "DESC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspection", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get inspection by id
|
||||
* @returns {Promise<inspection>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspection> {
|
||||
return await dataSource
|
||||
.getRepository(inspection)
|
||||
.createQueryBuilder("inspection")
|
||||
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
||||
.leftJoinAndSelect("inspection.inspectionVersionedPlan", "inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspection", err);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { inspectionVersionedPlan } from "../../../entity/unit/inspection/inspectionVersionedPlan";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionVersionedPlanService {
|
||||
/**
|
||||
* @description get all inspectionVersionedPlans
|
||||
* @returns {Promise<Array<inspectionVersionedPlan>>}
|
||||
*/
|
||||
static async getAllForInspectionPlan(inspectionPlanId: string): Promise<Array<inspectionVersionedPlan>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionVersionedPlan)
|
||||
.createQueryBuilder("inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.where({ inspectionPlanId })
|
||||
.orderBy("version", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionVersionedPlan", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get inspectionVersionedPlan by id
|
||||
* @returns {Promise<inspectionVersionedPlan>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspectionVersionedPlan> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionVersionedPlan)
|
||||
.createQueryBuilder("inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionVersionedPlan", err);
|
||||
});
|
||||
}
|
||||
}
|
43
src/service/unit/vehicle/vehicleService.ts
Normal file
43
src/service/unit/vehicle/vehicleService.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { vehicle } from "../../../entity/unit/vehicle/vehicle";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class VehicleService {
|
||||
/**
|
||||
* @description get all vehicles
|
||||
* @returns {Promise<Array<vehicle>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<vehicle>> {
|
||||
return await dataSource
|
||||
.getRepository(vehicle)
|
||||
.createQueryBuilder("vehicle")
|
||||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "vehicle", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get vehicle by id
|
||||
* @returns {Promise<vehicle>}
|
||||
*/
|
||||
static async getById(id: string): Promise<vehicle> {
|
||||
return await dataSource
|
||||
.getRepository(vehicle)
|
||||
.createQueryBuilder("vehicle")
|
||||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "vehicle", err);
|
||||
});
|
||||
}
|
||||
}
|
41
src/service/unit/vehicle/vehicleTypeService.ts
Normal file
41
src/service/unit/vehicle/vehicleTypeService.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { vehicleType } from "../../../entity/unit/vehicle/vehicleType";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class VehicleTypeService {
|
||||
/**
|
||||
* @description get all vehicleTypes
|
||||
* @returns {Promise<Array<vehicleType>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<vehicleType>> {
|
||||
return await dataSource
|
||||
.getRepository(vehicleType)
|
||||
.createQueryBuilder("vehicleType")
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "vehicleType", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get vehicleType by id
|
||||
* @returns {Promise<vehicleType>}
|
||||
*/
|
||||
static async getById(id: string): Promise<vehicleType> {
|
||||
return await dataSource
|
||||
.getRepository(vehicleType)
|
||||
.createQueryBuilder("vehicleType")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "vehicleType", err);
|
||||
});
|
||||
}
|
||||
}
|
44
src/service/unit/wearable/wearableService.ts
Normal file
44
src/service/unit/wearable/wearableService.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { wearable } from "../../../entity/unit/wearable/wearable";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class WearableService {
|
||||
/**
|
||||
* @description get all wearables
|
||||
* @returns {Promise<Array<wearable>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<wearable>> {
|
||||
return await dataSource
|
||||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.leftJoinAndSelect("wearable.wearer", "wearer")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "wearable", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get wearable by id
|
||||
* @returns {Promise<wearable>}
|
||||
*/
|
||||
static async getById(id: string): Promise<wearable> {
|
||||
return await dataSource
|
||||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "wearable", err);
|
||||
});
|
||||
}
|
||||
}
|
41
src/service/unit/wearable/wearableTypeService.ts
Normal file
41
src/service/unit/wearable/wearableTypeService.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { wearableType } from "../../../entity/unit/wearable/wearableType";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class WearableTypeService {
|
||||
/**
|
||||
* @description get all wearableTypes
|
||||
* @returns {Promise<Array<wearableType>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<wearableType>> {
|
||||
return await dataSource
|
||||
.getRepository(wearableType)
|
||||
.createQueryBuilder("wearableType")
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "wearableType", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get wearableType by id
|
||||
* @returns {Promise<wearableType>}
|
||||
*/
|
||||
static async getById(id: string): Promise<wearableType> {
|
||||
return await dataSource
|
||||
.getRepository(wearableType)
|
||||
.createQueryBuilder("wearableType")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "wearableType", err);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,14 +1,8 @@
|
|||
import type { EquipmentViewModel } from "../equipment/equipment.models";
|
||||
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
||||
import type { WearableViewModel } from "../wearable/wearable.models";
|
||||
import { EquipmentViewModel } from "./equipment/equipment.models";
|
||||
import { VehicleViewModel } from "./vehicle/vehicle.models";
|
||||
import { WearableViewModel } from "./wearable/wearable.models";
|
||||
|
||||
export type DamageReportViewModel = {
|
||||
id: string;
|
||||
reported: Date;
|
||||
status: string;
|
||||
done: boolean;
|
||||
description: string;
|
||||
providedImage: Array<string>;
|
||||
export type DamageReportAssigned = {
|
||||
relatedId: string;
|
||||
} & (
|
||||
| {
|
||||
|
@ -25,8 +19,19 @@ export type DamageReportViewModel = {
|
|||
}
|
||||
);
|
||||
|
||||
export type DamageReportViewModel = {
|
||||
id: string;
|
||||
reported: Date;
|
||||
status: string;
|
||||
done: boolean;
|
||||
description: string;
|
||||
imageCount: number;
|
||||
reportedBy: string;
|
||||
} & DamageReportAssigned;
|
||||
|
||||
export interface CreateDamageReportViewModel {
|
||||
description: string;
|
||||
reportedBy: string;
|
||||
affectedId: string;
|
||||
affected: "equipment" | "vehicle" | "wearable";
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import type { EquipmentTypeViewModel } from "../equipmentType/equipmentType.models";
|
||||
import type { InspectionViewModel } from "../inspection/inspection.models";
|
||||
import type { EquipmentTypeViewModel } from "./equipmentType.models";
|
||||
|
||||
export interface EquipmentViewModel {
|
||||
id: string;
|
||||
|
@ -10,7 +9,6 @@ export interface EquipmentViewModel {
|
|||
decommissioned?: Date;
|
||||
equipmentTypeId: string;
|
||||
equipmentType: EquipmentTypeViewModel;
|
||||
inspections: Array<InspectionViewModel>;
|
||||
}
|
||||
|
||||
export interface CreateEquipmentViewModel {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import type { InspectionPlanViewModel } from "../inspectionPlan/inspectionPlan.models";
|
||||
|
||||
export interface EquipmentTypeViewModel {
|
||||
id: string;
|
||||
type: string;
|
||||
description: string;
|
||||
inspectionPlans: Array<InspectionPlanViewModel>;
|
||||
}
|
||||
|
||||
export interface CreateEquipmentTypeViewModel {
|
|
@ -1,8 +1,9 @@
|
|||
import type { EquipmentViewModel } from "../equipment/equipment.models";
|
||||
import type {
|
||||
InspectionPlanViewModel,
|
||||
InspectionPointViewModel,
|
||||
InspectionVersionedPlanViewModel,
|
||||
} from "../inspectionPlan/inspectionPlan.models";
|
||||
} from "./inspectionPlan.models";
|
||||
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
||||
|
||||
export type InspectionViewModel = {
|
||||
|
@ -33,5 +34,6 @@ export interface InspectionPointResultViewModel {
|
|||
inspectionId: string;
|
||||
inspectionVersionedPlanId: string;
|
||||
inspectionPointId: string;
|
||||
inspectionPoint: InspectionPointViewModel;
|
||||
value: string;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ export interface InspectionPointViewModel {
|
|||
description: string;
|
||||
type: InspectionPointEnum;
|
||||
min?: number;
|
||||
max?: number;
|
||||
sort: number;
|
||||
}
|
||||
|
||||
export interface CreateInspectionPlanViewModel {
|
|
@ -1,5 +1,4 @@
|
|||
import type { InspectionViewModel } from "../inspection/inspection.models";
|
||||
import type { VehicleTypeViewModel } from "../vehicleType/vehicleType.models";
|
||||
import type { VehicleTypeViewModel } from "./vehicleType.models";
|
||||
|
||||
export interface VehicleViewModel {
|
||||
id: string;
|
||||
|
@ -10,7 +9,6 @@ export interface VehicleViewModel {
|
|||
decommissioned?: Date;
|
||||
vehicleTypeId: string;
|
||||
vehicleType: VehicleTypeViewModel;
|
||||
inspections: Array<InspectionViewModel>;
|
||||
}
|
||||
|
||||
export interface CreateVehicleViewModel {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import type { InspectionPlanViewModel } from "../inspectionPlan/inspectionPlan.models";
|
||||
|
||||
export interface VehicleTypeViewModel {
|
||||
id: string;
|
||||
type: string;
|
||||
description: string;
|
||||
inspectionPlans: Array<InspectionPlanViewModel>;
|
||||
}
|
||||
|
||||
export interface CreateVehicleTypeViewModel {
|
|
@ -1,5 +1,5 @@
|
|||
import { MemberViewModel } from "../../club/member/member.models";
|
||||
import type { WearableTypeViewModel } from "../wearableType/wearableType.models";
|
||||
import type { WearableTypeViewModel } from "./wearableType.models";
|
||||
|
||||
export interface WearableViewModel {
|
||||
id: string;
|
||||
|
|
Loading…
Add table
Reference in a new issue