45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
|
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));
|
||
|
}
|
||
|
}
|