63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { inspectionPlan } from "../../../../entity/unit/inspection/inspectionPlan";
|
|
import {
|
|
InspectionPlanRelated,
|
|
InspectionPlanViewModel,
|
|
} from "../../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
|
import EquipmentFactory from "../equipment/equipment";
|
|
import EquipmentTypeFactory from "../equipment/equipmentType";
|
|
import VehicleFactory from "../vehicle/vehicle";
|
|
import VehicleTypeFactory from "../vehicle/vehicleType";
|
|
import WearableTypeFactory from "../wearable/wearableType";
|
|
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 {
|
|
let related: InspectionPlanRelated;
|
|
if (record?.equipmentTypeId) {
|
|
related = {
|
|
relatedId: record.equipmentTypeId,
|
|
assigned: "equipment",
|
|
related: EquipmentTypeFactory.mapToSingle(record.equipmentType),
|
|
};
|
|
} else if (record?.vehicleTypeId) {
|
|
related = {
|
|
relatedId: record.vehicleTypeId,
|
|
assigned: "vehicle",
|
|
related: VehicleTypeFactory.mapToSingle(record.vehicleType),
|
|
};
|
|
} else {
|
|
related = {
|
|
relatedId: record.wearableTypeId,
|
|
assigned: "wearable",
|
|
related: WearableTypeFactory.mapToSingle(record.wearableType),
|
|
};
|
|
}
|
|
|
|
return {
|
|
id: record.id,
|
|
title: record.title,
|
|
inspectionInterval: record.inspectionInterval,
|
|
remindTime: record.remindTime,
|
|
version: record?.latestVersionedPlan?.version ?? 0,
|
|
created: record.createdAt,
|
|
inspectionPoints: record.latestVersionedPlan
|
|
? InspectionPointFactory.mapToBase(record.latestVersionedPlan.inspectionPoints)
|
|
: [],
|
|
...related,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @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));
|
|
}
|
|
}
|