factory and restructure view models
This commit is contained in:
parent
fcbfe560c3
commit
117ced38ab
33 changed files with 479 additions and 46 deletions
|
@ -23,33 +23,36 @@ export class damageReport {
|
||||||
@Column({ type: "varchar", length: 255 })
|
@Column({ type: "varchar", length: 255 })
|
||||||
reportedBy: string;
|
reportedBy: string;
|
||||||
|
|
||||||
@Column({ nullable: true, default: null })
|
@Column({ type: "int", default: 0 })
|
||||||
equipmentId: string;
|
imageCount: number;
|
||||||
|
|
||||||
@Column({ nullable: true, default: null })
|
@Column({ nullable: true, default: null })
|
||||||
vehicleId: string;
|
equipmentId?: string;
|
||||||
|
|
||||||
@Column({ nullable: true, default: null })
|
@Column({ nullable: true, default: null })
|
||||||
wearableId: string;
|
vehicleId?: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true, default: null })
|
||||||
|
wearableId?: string;
|
||||||
|
|
||||||
@ManyToOne(() => equipment, {
|
@ManyToOne(() => equipment, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
equipment: equipment;
|
equipment?: equipment;
|
||||||
|
|
||||||
@ManyToOne(() => vehicle, {
|
@ManyToOne(() => vehicle, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
vehicle: vehicle;
|
vehicle?: vehicle;
|
||||||
|
|
||||||
@ManyToOne(() => wearable, {
|
@ManyToOne(() => wearable, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
wearable: wearable;
|
wearable?: wearable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,10 @@ export class inspection {
|
||||||
inspectionVersionedPlanId: string;
|
inspectionVersionedPlanId: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
equipmentId: string;
|
equipmentId?: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
vehicleId: string;
|
vehicleId?: string;
|
||||||
|
|
||||||
@ManyToOne(() => inspectionPlan, {
|
@ManyToOne(() => inspectionPlan, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import { equipment } from "../equipment/equipment";
|
import { equipment } from "../equipment/equipment";
|
||||||
import { vehicle } from "../vehicle/vehicle";
|
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";
|
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
@ -22,16 +22,24 @@ export class inspectionPlan {
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
equipmentId: string;
|
equipmentId?: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
vehicleId: string;
|
vehicleId?: string;
|
||||||
|
|
||||||
@ManyToOne(() => equipment)
|
@ManyToOne(() => equipment, {
|
||||||
equipment: equipment;
|
nullable: true,
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
onUpdate: "RESTRICT",
|
||||||
|
})
|
||||||
|
equipment?: equipment;
|
||||||
|
|
||||||
@ManyToOne(() => vehicle)
|
@ManyToOne(() => vehicle, {
|
||||||
vehicle: vehicle;
|
nullable: true,
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
onUpdate: "RESTRICT",
|
||||||
|
})
|
||||||
|
vehicle?: vehicle;
|
||||||
|
|
||||||
@OneToMany(() => inspectionVersionedPlan, (ivp) => ivp.inspectionPlan, {
|
@OneToMany(() => inspectionVersionedPlan, (ivp) => ivp.inspectionPlan, {
|
||||||
cascade: ["insert"],
|
cascade: ["insert"],
|
||||||
|
|
|
@ -28,10 +28,10 @@ export class inspectionPoint {
|
||||||
type: InspectionPointEnum;
|
type: InspectionPointEnum;
|
||||||
|
|
||||||
@Column({ type: "int", nullable: true, default: null })
|
@Column({ type: "int", nullable: true, default: null })
|
||||||
min: number;
|
min?: number;
|
||||||
|
|
||||||
@Column({ type: "int", nullable: true, default: null })
|
@Column({ type: "int", nullable: true, default: null })
|
||||||
max: number;
|
max?: number;
|
||||||
|
|
||||||
@Column({ type: "int", default: 0 })
|
@Column({ type: "int", default: 0 })
|
||||||
sort: number;
|
sort: number;
|
||||||
|
|
|
@ -29,7 +29,7 @@ export class wearable {
|
||||||
wearableTypeId: string;
|
wearableTypeId: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
wearerId: string;
|
wearerId?: string;
|
||||||
|
|
||||||
@ManyToOne(() => wearableType, {
|
@ManyToOne(() => wearableType, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
@ -39,11 +39,11 @@ export class wearable {
|
||||||
wearableType: wearableType;
|
wearableType: wearableType;
|
||||||
|
|
||||||
@ManyToOne(() => member, {
|
@ManyToOne(() => member, {
|
||||||
nullable: false,
|
nullable: true,
|
||||||
onDelete: "SET NULL",
|
onDelete: "SET NULL",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
wearer: member;
|
wearer?: member;
|
||||||
|
|
||||||
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
||||||
reports: damageReport[];
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,9 @@ export default abstract class DamageReportService {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.getRepository(damageReport)
|
.getRepository(damageReport)
|
||||||
.createQueryBuilder("damageReport")
|
.createQueryBuilder("damageReport")
|
||||||
|
.leftJoinAndSelect("damageReport.equipment", "equipment")
|
||||||
|
.leftJoinAndSelect("damageReport.vehicle", "vehicle")
|
||||||
|
.leftJoinAndSelect("damageReport.wearable", "wearable")
|
||||||
.orderBy("type", "ASC")
|
.orderBy("type", "ASC")
|
||||||
.getMany()
|
.getMany()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
|
@ -23,6 +23,8 @@ export default abstract class InspectionPlanService {
|
||||||
: "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("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||||
|
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||||
|
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||||
.where(where)
|
.where(where)
|
||||||
.orderBy("title", "ASC")
|
.orderBy("title", "ASC")
|
||||||
.getMany()
|
.getMany()
|
||||||
|
@ -51,6 +53,8 @@ export default abstract class InspectionPlanService {
|
||||||
: "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("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||||
|
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||||
|
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||||
.where({ id })
|
.where({ id })
|
||||||
.getOneOrFail()
|
.getOneOrFail()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
|
@ -16,6 +16,8 @@ export default abstract class InspectionService {
|
||||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||||
|
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||||
|
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||||
.where(where)
|
.where(where)
|
||||||
.orderBy("createdAt", "DESC")
|
.orderBy("createdAt", "DESC")
|
||||||
.getMany()
|
.getMany()
|
||||||
|
@ -40,6 +42,8 @@ export default abstract class InspectionService {
|
||||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||||
|
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||||
|
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||||
.where({ id })
|
.where({ id })
|
||||||
.getOneOrFail()
|
.getOneOrFail()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
|
@ -12,6 +12,7 @@ export default abstract class WearableService {
|
||||||
.getRepository(wearable)
|
.getRepository(wearable)
|
||||||
.createQueryBuilder("wearable")
|
.createQueryBuilder("wearable")
|
||||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||||
|
.leftJoinAndSelect("wearable.wearer", "wearer")
|
||||||
.orderBy("name", "ASC")
|
.orderBy("name", "ASC")
|
||||||
.getMany()
|
.getMany()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
|
@ -1,15 +1,8 @@
|
||||||
import type { EquipmentViewModel } from "../equipment/equipment.models";
|
import { EquipmentViewModel } from "./equipment/equipment.models";
|
||||||
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
import { VehicleViewModel } from "./vehicle/vehicle.models";
|
||||||
import type { WearableViewModel } from "../wearable/wearable.models";
|
import { WearableViewModel } from "./wearable/wearable.models";
|
||||||
|
|
||||||
export type DamageReportViewModel = {
|
export type DamageReportAssigned = {
|
||||||
id: string;
|
|
||||||
reported: Date;
|
|
||||||
status: string;
|
|
||||||
done: boolean;
|
|
||||||
description: string;
|
|
||||||
providedImage: Array<string>;
|
|
||||||
reportedBy: string;
|
|
||||||
relatedId: string;
|
relatedId: string;
|
||||||
} & (
|
} & (
|
||||||
| {
|
| {
|
||||||
|
@ -26,6 +19,16 @@ export type DamageReportViewModel = {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export type DamageReportViewModel = {
|
||||||
|
id: string;
|
||||||
|
reported: Date;
|
||||||
|
status: string;
|
||||||
|
done: boolean;
|
||||||
|
description: string;
|
||||||
|
imageCount: number;
|
||||||
|
reportedBy: string;
|
||||||
|
} & DamageReportAssigned;
|
||||||
|
|
||||||
export interface CreateDamageReportViewModel {
|
export interface CreateDamageReportViewModel {
|
||||||
description: string;
|
description: string;
|
||||||
reportedBy: string;
|
reportedBy: string;
|
|
@ -1,5 +1,4 @@
|
||||||
import type { EquipmentTypeViewModel } from "../equipmentType/equipmentType.models";
|
import type { EquipmentTypeViewModel } from "./equipmentType.models";
|
||||||
import type { InspectionViewModel } from "../inspection/inspection.models";
|
|
||||||
|
|
||||||
export interface EquipmentViewModel {
|
export interface EquipmentViewModel {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -10,7 +9,6 @@ export interface EquipmentViewModel {
|
||||||
decommissioned?: Date;
|
decommissioned?: Date;
|
||||||
equipmentTypeId: string;
|
equipmentTypeId: string;
|
||||||
equipmentType: EquipmentTypeViewModel;
|
equipmentType: EquipmentTypeViewModel;
|
||||||
inspections: Array<InspectionViewModel>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateEquipmentViewModel {
|
export interface CreateEquipmentViewModel {
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import type { InspectionPlanViewModel } from "../inspectionPlan/inspectionPlan.models";
|
|
||||||
|
|
||||||
export interface EquipmentTypeViewModel {
|
export interface EquipmentTypeViewModel {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
description: string;
|
description: string;
|
||||||
inspectionPlans: Array<InspectionPlanViewModel>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateEquipmentTypeViewModel {
|
export interface CreateEquipmentTypeViewModel {
|
|
@ -1,8 +1,9 @@
|
||||||
import type { EquipmentViewModel } from "../equipment/equipment.models";
|
import type { EquipmentViewModel } from "../equipment/equipment.models";
|
||||||
import type {
|
import type {
|
||||||
InspectionPlanViewModel,
|
InspectionPlanViewModel,
|
||||||
|
InspectionPointViewModel,
|
||||||
InspectionVersionedPlanViewModel,
|
InspectionVersionedPlanViewModel,
|
||||||
} from "../inspectionPlan/inspectionPlan.models";
|
} from "./inspectionPlan.models";
|
||||||
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
||||||
|
|
||||||
export type InspectionViewModel = {
|
export type InspectionViewModel = {
|
||||||
|
@ -33,5 +34,6 @@ export interface InspectionPointResultViewModel {
|
||||||
inspectionId: string;
|
inspectionId: string;
|
||||||
inspectionVersionedPlanId: string;
|
inspectionVersionedPlanId: string;
|
||||||
inspectionPointId: string;
|
inspectionPointId: string;
|
||||||
|
inspectionPoint: InspectionPointViewModel;
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ export interface InspectionPointViewModel {
|
||||||
description: string;
|
description: string;
|
||||||
type: InspectionPointEnum;
|
type: InspectionPointEnum;
|
||||||
min?: number;
|
min?: number;
|
||||||
|
max?: number;
|
||||||
|
sort: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateInspectionPlanViewModel {
|
export interface CreateInspectionPlanViewModel {
|
|
@ -1,5 +1,4 @@
|
||||||
import type { InspectionViewModel } from "../inspection/inspection.models";
|
import type { VehicleTypeViewModel } from "./vehicleType.models";
|
||||||
import type { VehicleTypeViewModel } from "../vehicleType/vehicleType.models";
|
|
||||||
|
|
||||||
export interface VehicleViewModel {
|
export interface VehicleViewModel {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -10,7 +9,6 @@ export interface VehicleViewModel {
|
||||||
decommissioned?: Date;
|
decommissioned?: Date;
|
||||||
vehicleTypeId: string;
|
vehicleTypeId: string;
|
||||||
vehicleType: VehicleTypeViewModel;
|
vehicleType: VehicleTypeViewModel;
|
||||||
inspections: Array<InspectionViewModel>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateVehicleViewModel {
|
export interface CreateVehicleViewModel {
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import type { InspectionPlanViewModel } from "../inspectionPlan/inspectionPlan.models";
|
|
||||||
|
|
||||||
export interface VehicleTypeViewModel {
|
export interface VehicleTypeViewModel {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
description: string;
|
description: string;
|
||||||
inspectionPlans: Array<InspectionPlanViewModel>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateVehicleTypeViewModel {
|
export interface CreateVehicleTypeViewModel {
|
|
@ -1,5 +1,5 @@
|
||||||
import { MemberViewModel } from "../../club/member/member.models";
|
import { MemberViewModel } from "../../club/member/member.models";
|
||||||
import type { WearableTypeViewModel } from "../wearableType/wearableType.models";
|
import type { WearableTypeViewModel } from "./wearableType.models";
|
||||||
|
|
||||||
export interface WearableViewModel {
|
export interface WearableViewModel {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue