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 })
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ export class inspection {
|
|||
inspectionVersionedPlanId: string;
|
||||
|
||||
@Column()
|
||||
equipmentId: string;
|
||||
equipmentId?: string;
|
||||
|
||||
@Column()
|
||||
vehicleId: string;
|
||||
vehicleId?: string;
|
||||
|
||||
@ManyToOne(() => inspectionPlan, {
|
||||
nullable: false,
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -28,10 +28,10 @@ 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;
|
||||
|
|
|
@ -29,7 +29,7 @@ export class wearable {
|
|||
wearableTypeId: string;
|
||||
|
||||
@Column()
|
||||
wearerId: string;
|
||||
wearerId?: string;
|
||||
|
||||
@ManyToOne(() => wearableType, {
|
||||
nullable: false,
|
||||
|
@ -39,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));
|
||||
}
|
||||
}
|
|
@ -11,6 +11,9 @@ export default abstract class DamageReportService {
|
|||
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) => {
|
||||
|
|
|
@ -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)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||
.where(where)
|
||||
.orderBy("title", "ASC")
|
||||
.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)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -16,6 +16,8 @@ export default abstract class InspectionService {
|
|||
.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()
|
||||
|
@ -40,6 +42,8 @@ export default abstract class InspectionService {
|
|||
.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) => {
|
||||
|
|
|
@ -12,6 +12,7 @@ export default abstract class WearableService {
|
|||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.leftJoinAndSelect("wearable.wearer", "wearer")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
|
|
|
@ -1,15 +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>;
|
||||
reportedBy: string;
|
||||
export type DamageReportAssigned = {
|
||||
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 {
|
||||
description: string;
|
||||
reportedBy: string;
|
|
@ -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