command Handlers and schema update

This commit is contained in:
Julian Krauser 2025-05-29 10:31:40 +02:00
parent 0f6401953f
commit 7883bb7d7f
42 changed files with 1076 additions and 159 deletions

View file

@ -0,0 +1,22 @@
export interface CreateDamageReportCommand {
description: string;
reportedBy: string;
imageCount: number;
affectedId: string;
affected: "equipment" | "vehicle" | "wearable";
}
export interface UpdateDamageReportCommand {
id: string;
status: string;
done: boolean;
}
export interface UpdateDamageReportRelatedMaintenanceCommand {
id: string;
maintenanceId: string;
}
export interface DeleteDamageReportCommand {
id: string;
}

View file

@ -0,0 +1,100 @@
import { dataSource } from "../../data-source";
import { damageReport } from "../../entity/unit/damageReport";
import DatabaseActionException from "../../exceptions/databaseActionException";
import {
CreateDamageReportCommand,
UpdateDamageReportCommand,
DeleteDamageReportCommand,
UpdateDamageReportRelatedMaintenanceCommand,
} from "./damageReportCommand";
export default abstract class DamageReportCommandHandler {
/**
* @description create damageReport
* @param {CreateDamageReportCommand} createDamageReport
* @returns {Promise<number>}
*/
static async create(createDamageReport: CreateDamageReportCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(damageReport)
.values({
status: "eingereicht",
description: createDamageReport.description,
reportedBy: createDamageReport.reportedBy,
imageCount: createDamageReport.imageCount,
equipmentId: createDamageReport.affected == "equipment" ? createDamageReport.affectedId : null,
vehicleId: createDamageReport.affected == "vehicle" ? createDamageReport.affectedId : null,
wearableId: createDamageReport.affected == "wearable" ? createDamageReport.affectedId : null,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "damageReport", err);
});
}
/**
* @description update damageReport
* @param {UpdateDamageReportCommand} updateDamageReport
* @returns {Promise<void>}
*/
static async update(updateDamageReport: UpdateDamageReportCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(damageReport)
.set({
status: updateDamageReport.status,
done: updateDamageReport.done,
})
.where("id = :id", { id: updateDamageReport.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "damageReport", err);
});
}
/**
* @description update damageReport related maintenance
* @param {UpdateDamageReportCommand} updateDamageReport
* @returns {Promise<void>}
*/
static async updateRelatedMaintenance(
updateDamageReport: UpdateDamageReportRelatedMaintenanceCommand
): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(damageReport)
.set({
maintenanceId: updateDamageReport.maintenanceId,
})
.where("id = :id", { id: updateDamageReport.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "damageReport->maintenance", err);
});
}
/**
* @description delete damageReport
* @param {DeleteDamageReportCommand} deleteDamageReport
* @returns {Promise<void>}
*/
static async delete(deleteDamageReport: DeleteDamageReportCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(damageReport)
.where("id = :id", { id: deleteDamageReport.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "damageReport", err);
});
}
}

View file

@ -0,0 +1,20 @@
export interface CreateEquipmentCommand {
code?: string;
name: string;
location: string;
commissioned: Date;
equipmentTypeId: string;
}
export interface UpdateEquipmentCommand {
id: string;
code?: string;
name: string;
location: string;
commissioned: Date;
decommissioned?: Date;
}
export interface DeleteEquipmentCommand {
id: string;
}

View file

@ -0,0 +1,74 @@
import { dataSource } from "../../../data-source";
import { equipment } from "../../../entity/unit/equipment/equipment";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateEquipmentCommand, UpdateEquipmentCommand, DeleteEquipmentCommand } from "./equipmentCommand";
export default abstract class EquipmentCommandHandler {
/**
* @description create equipment
* @param {CreateEquipmentCommand} createEquipment
* @returns {Promise<number>}
*/
static async create(createEquipment: CreateEquipmentCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(equipment)
.values({
code: createEquipment.code,
name: createEquipment.name,
location: createEquipment.location,
commissioned: createEquipment.commissioned,
equipmentTypeId: createEquipment.equipmentTypeId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "equipment", err);
});
}
/**
* @description update equipment
* @param {UpdateEquipmentCommand} updateEquipment
* @returns {Promise<void>}
*/
static async update(updateEquipment: UpdateEquipmentCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(equipment)
.set({
code: updateEquipment.code,
name: updateEquipment.name,
location: updateEquipment.location,
commissioned: updateEquipment.commissioned,
decommissioned: updateEquipment.decommissioned,
})
.where("id = :id", { id: updateEquipment.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "equipment", err);
});
}
/**
* @description delete equipment
* @param {DeleteEquipmentCommand} deleteEquipment
* @returns {Promise<void>}
*/
static async delete(deleteEquipment: DeleteEquipmentCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(equipment)
.where("id = :id", { id: deleteEquipment.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "equipment", err);
});
}
}

View file

@ -0,0 +1,14 @@
export interface CreateEquipmentTypeCommand {
type: string;
description: string;
}
export interface UpdateEquipmentTypeCommand {
id: string;
type: string;
description: string;
}
export interface DeleteEquipmentTypeCommand {
id: string;
}

View file

@ -0,0 +1,72 @@
import { dataSource } from "../../../data-source";
import { equipmentType } from "../../../entity/unit/equipment/equipmentType";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import {
CreateEquipmentTypeCommand,
UpdateEquipmentTypeCommand,
DeleteEquipmentTypeCommand,
} from "./equipmentTypeCommand";
export default abstract class EquipmentTypeCommandHandler {
/**
* @description create equipmentType
* @param {CreateEquipmentTypeCommand} createEquipmentType
* @returns {Promise<number>}
*/
static async create(createEquipmentType: CreateEquipmentTypeCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(equipmentType)
.values({
type: createEquipmentType.type,
description: createEquipmentType.description,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "equipmentType", err);
});
}
/**
* @description update equipmentType
* @param {UpdateEquipmentTypeCommand} updateEquipmentType
* @returns {Promise<void>}
*/
static async update(updateEquipmentType: UpdateEquipmentTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(equipmentType)
.set({
type: updateEquipmentType.type,
description: updateEquipmentType.description,
})
.where("id = :id", { id: updateEquipmentType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "equipmentType", err);
});
}
/**
* @description delete equipmentType
* @param {DeleteEquipmentTypeCommand} deleteEquipmentType
* @returns {Promise<void>}
*/
static async delete(deleteEquipmentType: DeleteEquipmentTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(equipmentType)
.where("id = :id", { id: deleteEquipmentType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "equipmentType", err);
});
}
}

View file

@ -0,0 +1,17 @@
export interface CreateInspectionCommand {
context: string;
nextInspection?: Date;
inspectionPlanId: string;
relatedId: string;
assigned: "vehicle" | "equipment";
}
export interface UpdateInspectionCommand {
id: string;
context: string;
nextInspection?: Date;
}
export interface DeleteInspectionCommand {
id: string;
}

View file

@ -0,0 +1,76 @@
import { dataSource } from "../../../data-source";
import { inspection } from "../../../entity/unit/inspection/inspection";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import InspectionVersionedPlanService from "../../../service/unit/inspection/inspectionVersionedPlanService";
import { CreateInspectionCommand, UpdateInspectionCommand, DeleteInspectionCommand } from "./inspectionCommand";
export default abstract class InspectionCommandHandler {
/**
* @description create inspection
* @param {CreateInspectionCommand} createInspection
* @returns {Promise<number>}
*/
static async create(createInspection: CreateInspectionCommand): Promise<number> {
let latestVersionedPlan = await InspectionVersionedPlanService.getLatestForInspectionPlan(
createInspection.inspectionPlanId
);
return await dataSource
.createQueryBuilder()
.insert()
.into(inspection)
.values({
context: createInspection.context,
nextInspection: createInspection.nextInspection,
inspectionPlanId: createInspection.inspectionPlanId,
inspectionVersionedPlanId: latestVersionedPlan.id,
equipmentId: createInspection.assigned == "equipment" ? createInspection.relatedId : null,
vehicleId: createInspection.assigned == "vehicle" ? createInspection.relatedId : null,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "inspection", err);
});
}
/**
* @description update inspection
* @param {UpdateInspectionCommand} updateInspection
* @returns {Promise<void>}
*/
static async update(updateInspection: UpdateInspectionCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(inspection)
.set({
context: updateInspection.context,
nextInspection: updateInspection.nextInspection,
})
.where("id = :id", { id: updateInspection.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "inspection", err);
});
}
/**
* @description delete inspection
* @param {DeleteInspectionCommand} deleteInspection
* @returns {Promise<void>}
*/
static async delete(deleteInspection: DeleteInspectionCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(inspection)
.where("id = :id", { id: deleteInspection.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "inspection", err);
});
}
}

View file

@ -0,0 +1,20 @@
import { PlanTimeDefinition } from "../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
export interface CreateInspectionPlanCommand {
title: string;
inspectionInterval: PlanTimeDefinition;
remindTime: PlanTimeDefinition;
relatedId: string;
assigned: "vehicle" | "equipment";
}
export interface UpdateInspectionPlanCommand {
id: string;
title: string;
inspectionInterval: PlanTimeDefinition;
remindTime?: PlanTimeDefinition;
}
export interface DeleteInspectionPlanCommand {
id: string;
}

View file

@ -0,0 +1,76 @@
import { dataSource } from "../../../data-source";
import { inspectionPlan } from "../../../entity/unit/inspection/inspectionPlan";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import {
CreateInspectionPlanCommand,
UpdateInspectionPlanCommand,
DeleteInspectionPlanCommand,
} from "./inspectionPlanCommand";
export default abstract class InspectionPlanCommandHandler {
/**
* @description create inspectionPlan
* @param {CreateInspectionPlanCommand} createInspectionPlan
* @returns {Promise<number>}
*/
static async create(createInspectionPlan: CreateInspectionPlanCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(inspectionPlan)
.values({
title: createInspectionPlan.title,
inspectionInterval: createInspectionPlan.inspectionInterval,
remindTime: createInspectionPlan.remindTime,
equipmentId: createInspectionPlan.assigned == "equipment" ? createInspectionPlan.relatedId : null,
vehicleId: createInspectionPlan.assigned == "vehicle" ? createInspectionPlan.relatedId : null,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "inspectionPlan", err);
});
}
/**
* @description update inspectionPlan
* @param {UpdateInspectionPlanCommand} updateInspectionPlan
* @returns {Promise<void>}
*/
static async update(updateInspectionPlan: UpdateInspectionPlanCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(inspectionPlan)
.set({
title: updateInspectionPlan.title,
inspectionInterval: updateInspectionPlan.inspectionInterval,
remindTime: updateInspectionPlan.remindTime,
})
.where("id = :id", { id: updateInspectionPlan.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "inspectionPlan", err);
});
}
/**
* @description delete inspectionPlan
* @param {DeleteInspectionPlanCommand} deleteInspectionPlan
* @returns {Promise<void>}
*/
static async delete(deleteInspectionPlan: DeleteInspectionPlanCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(inspectionPlan)
.where("id = :id", { id: deleteInspectionPlan.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "inspectionPlan", err);
});
}
}

View file

@ -0,0 +1,11 @@
import { InspectionPointEnum } from "../../../enums/inspectionEnum";
export interface CreateInspectionPointCommand {
title: string;
description: string;
type: InspectionPointEnum;
min?: number;
max?: number;
sort: number;
versionedPointId: string;
}

View file

@ -0,0 +1,34 @@
import { dataSource } from "../../../data-source";
import { inspectionPoint } from "../../../entity/unit/inspection/inspectionPoint";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateInspectionPointCommand } from "./inspectionPointCommand";
export default abstract class InspectionPointCommandHandler {
/**
* @description create inspectionPoint
* @param {CreateInspectionPointCommand} createInspectionPoint
* @returns {Promise<number>}
*/
static async create(createInspectionPoint: CreateInspectionPointCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(inspectionPoint)
.values({
title: createInspectionPoint.title,
description: createInspectionPoint.description,
type: createInspectionPoint.type,
min: createInspectionPoint.min,
max: createInspectionPoint.max,
sort: createInspectionPoint.sort,
versionedPlanId: createInspectionPoint.versionedPointId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "inspectionPoint", err);
});
}
}

View file

@ -0,0 +1,5 @@
export interface CreateInspectionPointResultCommand {
inspectionId: string;
inspectionPointId: string;
value: string;
}

View file

@ -0,0 +1,31 @@
import { dataSource } from "../../../data-source";
import { inspectionPointResult } from "../../../entity/unit/inspection/inspectionPointResult";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateInspectionPointResultCommand } from "./inspectionPointResultCommand";
export default abstract class InspectionPointResultCommandHandler {
/**
* @description create inspectionPointResult
* @param {CreateInspectionPointResultCommand} createInspectionPointResult
* @returns {Promise<number>}
*/
static async createOrUpdate(createInspectionPointResult: CreateInspectionPointResultCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(inspectionPointResult)
.values({
inspectionId: createInspectionPointResult.inspectionId,
inspectionPointId: createInspectionPointResult.inspectionPointId,
value: createInspectionPointResult.value,
})
.orUpdate(["value"], ["inspectionId", "inspectionPointId"])
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "inspectionPointResult", err);
});
}
}

View file

@ -0,0 +1,3 @@
export interface CreateInspectionVersionedPlanCommand {
inspectionPlanId: string;
}

View file

@ -0,0 +1,28 @@
import { dataSource } from "../../../data-source";
import { inspectionVersionedPlan } from "../../../entity/unit/inspection/inspectionVersionedPlan";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateInspectionVersionedPlanCommand } from "./inspectionVersionedPlanCommand";
export default abstract class InspectionVersionedPlanCommandHandler {
/**
* @description create inspectionVersionedPlan
* @param {CreateInspectionVersionedPlanCommand} createInspectionVersionedPlan
* @returns {Promise<number>}
*/
static async create(createInspectionVersionedPlan: CreateInspectionVersionedPlanCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(inspectionVersionedPlan)
.values({
inspectionPlanId: createInspectionVersionedPlan.inspectionPlanId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "inspectionVersionedPlan", err);
});
}
}

View file

@ -0,0 +1,16 @@
export interface CreateMaintenanceCommand {
description: string;
affectedId: string;
affected: "equipment" | "vehicle" | "wearable";
}
export interface UpdateMaintenanceCommand {
id: string;
status: string;
done: boolean;
description: string;
}
export interface DeleteMaintenanceCommand {
id: string;
}

View file

@ -0,0 +1,72 @@
import { dataSource } from "../../data-source";
import { maintenance } from "../../entity/unit/maintenance";
import DatabaseActionException from "../../exceptions/databaseActionException";
import { CreateMaintenanceCommand, UpdateMaintenanceCommand, DeleteMaintenanceCommand } from "./maintenanceCommand";
export default abstract class MaintenanceCommandHandler {
/**
* @description create maintenance
* @param {CreateMaintenanceCommand} createMaintenance
* @returns {Promise<number>}
*/
static async create(createMaintenance: CreateMaintenanceCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(maintenance)
.values({
status: "gestartet",
description: createMaintenance.description,
equipmentId: createMaintenance.affected == "equipment" ? createMaintenance.affectedId : null,
vehicleId: createMaintenance.affected == "vehicle" ? createMaintenance.affectedId : null,
wearableId: createMaintenance.affected == "wearable" ? createMaintenance.affectedId : null,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "maintenance", err);
});
}
/**
* @description update maintenance
* @param {UpdateMaintenanceCommand} updateMaintenance
* @returns {Promise<void>}
*/
static async update(updateMaintenance: UpdateMaintenanceCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(maintenance)
.set({
status: updateMaintenance.status,
done: updateMaintenance.done,
description: updateMaintenance.description,
})
.where("id = :id", { id: updateMaintenance.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "maintenance", err);
});
}
/**
* @description delete maintenance
* @param {DeleteMaintenanceCommand} deleteMaintenance
* @returns {Promise<void>}
*/
static async delete(deleteMaintenance: DeleteMaintenanceCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(maintenance)
.where("id = :id", { id: deleteMaintenance.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "maintenance", err);
});
}
}

View file

@ -0,0 +1,20 @@
export interface CreateVehicleCommand {
code?: string;
name: string;
location: string;
commissioned: Date;
vehicleTypeId: string;
}
export interface UpdateVehicleCommand {
id: string;
code?: string;
name: string;
location: string;
commissioned: Date;
decommissioned?: Date;
}
export interface DeleteVehicleCommand {
id: string;
}

View file

@ -0,0 +1,73 @@
import { dataSource } from "../../../data-source";
import { vehicle } from "../../../entity/unit/vehicle/vehicle";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateVehicleCommand, UpdateVehicleCommand, DeleteVehicleCommand } from "./vehicleCommand";
export default abstract class VehicleCommandHandler {
/**
* @description create vehicle
* @param {CreateVehicleCommand} createVehicle
* @returns {Promise<number>}
*/
static async create(createVehicle: CreateVehicleCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(vehicle)
.values({
code: createVehicle.code,
name: createVehicle.name,
location: createVehicle.location,
commissioned: createVehicle.commissioned,
vehicleTypeId: createVehicle.vehicleTypeId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "vehicle", err);
});
}
/**
* @description update vehicle
* @param {UpdateVehicleCommand} updateVehicle
* @returns {Promise<void>}
*/
static async update(updateVehicle: UpdateVehicleCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(vehicle)
.set({
code: updateVehicle.code,
name: updateVehicle.name,
location: updateVehicle.location,
commissioned: updateVehicle.commissioned,
})
.where("id = :id", { id: updateVehicle.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "vehicle", err);
});
}
/**
* @description delete vehicle
* @param {DeleteVehicleCommand} deleteVehicle
* @returns {Promise<void>}
*/
static async delete(deleteVehicle: DeleteVehicleCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(vehicle)
.where("id = :id", { id: deleteVehicle.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "vehicle", err);
});
}
}

View file

@ -0,0 +1,14 @@
export interface CreateVehicleTypeCommand {
type: string;
description: string;
}
export interface UpdateVehicleTypeCommand {
id: string;
type: string;
description: string;
}
export interface DeleteVehicleTypeCommand {
id: string;
}

View file

@ -0,0 +1,68 @@
import { dataSource } from "../../../data-source";
import { vehicleType } from "../../../entity/unit/vehicle/vehicleType";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateVehicleTypeCommand, UpdateVehicleTypeCommand, DeleteVehicleTypeCommand } from "./vehicleTypeCommand";
export default abstract class VehicleTypeCommandHandler {
/**
* @description create vehicleType
* @param {CreateVehicleTypeCommand} createVehicleType
* @returns {Promise<number>}
*/
static async create(createVehicleType: CreateVehicleTypeCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(vehicleType)
.values({
type: createVehicleType.type,
description: createVehicleType.description,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "vehicleType", err);
});
}
/**
* @description update vehicleType
* @param {UpdateVehicleTypeCommand} updateVehicleType
* @returns {Promise<void>}
*/
static async update(updateVehicleType: UpdateVehicleTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(vehicleType)
.set({
type: updateVehicleType.type,
description: updateVehicleType.description,
})
.where("id = :id", { id: updateVehicleType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "vehicleType", err);
});
}
/**
* @description delete vehicleType
* @param {DeleteVehicleTypeCommand} deleteVehicleType
* @returns {Promise<void>}
*/
static async delete(deleteVehicleType: DeleteVehicleTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(vehicleType)
.where("id = :id", { id: deleteVehicleType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "vehicleType", err);
});
}
}

View file

@ -0,0 +1,22 @@
export interface CreateWearableCommand {
code?: string;
name: string;
location: string;
commissioned: Date;
wearableTypeId: string;
wearerId?: string;
}
export interface UpdateWearableCommand {
id: string;
code?: string;
name: string;
location: string;
commissioned: Date;
decommissioned?: Date;
wearerId?: string;
}
export interface DeleteWearableCommand {
id: string;
}

View file

@ -0,0 +1,76 @@
import { dataSource } from "../../../data-source";
import { wearable } from "../../../entity/unit/wearable/wearable";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateWearableCommand, UpdateWearableCommand, DeleteWearableCommand } from "./wearableCommand";
export default abstract class WearableCommandHandler {
/**
* @description create wearable
* @param {CreateWearableCommand} createWearable
* @returns {Promise<number>}
*/
static async create(createWearable: CreateWearableCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(wearable)
.values({
code: createWearable.code,
name: createWearable.name,
location: createWearable.location,
commissioned: createWearable.commissioned,
wearableTypeId: createWearable.wearableTypeId,
wearerId: createWearable.wearerId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "wearable", err);
});
}
/**
* @description update wearable
* @param {UpdateWearableCommand} updateWearable
* @returns {Promise<void>}
*/
static async update(updateWearable: UpdateWearableCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(wearable)
.set({
code: updateWearable.code,
name: updateWearable.name,
location: updateWearable.location,
commissioned: updateWearable.commissioned,
decommissioned: updateWearable.decommissioned,
wearerId: updateWearable.wearerId,
})
.where("id = :id", { id: updateWearable.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "wearable", err);
});
}
/**
* @description delete wearable
* @param {DeleteWearableCommand} deleteWearable
* @returns {Promise<void>}
*/
static async delete(deleteWearable: DeleteWearableCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(wearable)
.where("id = :id", { id: deleteWearable.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "wearable", err);
});
}
}

View file

@ -0,0 +1,14 @@
export interface CreateWearableTypeCommand {
type: string;
description: string;
}
export interface UpdateWearableTypeCommand {
id: string;
type: string;
description: string;
}
export interface DeleteWearableTypeCommand {
id: string;
}

View file

@ -0,0 +1,68 @@
import { dataSource } from "../../../data-source";
import { wearableType } from "../../../entity/unit/wearable/wearableType";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import { CreateWearableTypeCommand, UpdateWearableTypeCommand, DeleteWearableTypeCommand } from "./wearableTypeCommand";
export default abstract class WearableTypeCommandHandler {
/**
* @description create wearableType
* @param {CreateWearableTypeCommand} createWearableType
* @returns {Promise<number>}
*/
static async create(createWearableType: CreateWearableTypeCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(wearableType)
.values({
type: createWearableType.type,
description: createWearableType.description,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new DatabaseActionException("CREATE", "wearableType", err);
});
}
/**
* @description update wearableType
* @param {UpdateWearableTypeCommand} updateWearableType
* @returns {Promise<void>}
*/
static async update(updateWearableType: UpdateWearableTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(wearableType)
.set({
type: updateWearableType.type,
description: updateWearableType.description,
})
.where("id = :id", { id: updateWearableType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("UPDATE", "wearableType", err);
});
}
/**
* @description delete wearableType
* @param {DeleteWearableTypeCommand} deleteWearableType
* @returns {Promise<void>}
*/
static async delete(deleteWearableType: DeleteWearableTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(wearableType)
.where("id = :id", { id: deleteWearableType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new DatabaseActionException("DELETE", "wearableType", err);
});
}
}

View file

@ -31,7 +31,7 @@ export class damageReport {
equipmentId?: string;
@Column({ nullable: true, default: null })
maintenanceId: string;
maintenanceId?: string;
@Column({ nullable: true, default: null })
vehicleId?: string;

View file

@ -1,21 +1,18 @@
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm";
import { inspection } from "./inspection";
import { inspectionPoint } from "./inspectionPoint";
@Entity()
export class inspectionPointResult {
@PrimaryGeneratedColumn("uuid")
id: string;
@PrimaryColumn()
inspectionId: string;
@PrimaryColumn()
inspectionPointId: string;
@Column({ type: "text" })
value: string;
@Column()
inspectionId: string;
@Column()
inspectionPointId: string;
@ManyToOne(() => inspection, {
nullable: false,
onDelete: "CASCADE",

View file

@ -126,10 +126,9 @@ export const inspection_table = new Table({
export const inspection_point_result_table = new Table({
name: "inspection_point_result",
columns: [
{ name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary },
{ name: "inspectionId", ...getTypeByORM("uuid"), isPrimary: true },
{ name: "inspectionPointId", ...getTypeByORM("uuid"), isPrimary: true },
{ name: "value", ...getTypeByORM("text") },
{ name: "inspectionId", ...getTypeByORM("uuid") },
{ name: "inspectionPointId", ...getTypeByORM("uuid") },
],
foreignKeys: [
new TableForeignKey({

View file

@ -21,23 +21,4 @@ export default abstract class InspectionPointResultService {
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);
});
}
}

View file

@ -23,6 +23,27 @@ export default abstract class InspectionVersionedPlanService {
});
}
/**
* @description get latest inspectionVersionedPlan for plan
* @returns {Promise<Array<inspectionVersionedPlan>>}
*/
static async getLatestForInspectionPlan(inspectionPlanId: string): Promise<inspectionVersionedPlan> {
return await dataSource
.getRepository(inspectionVersionedPlan)
.createQueryBuilder("inspectionVersionedPlan")
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
.where({ inspectionPlanId })
.orderBy("inspectionVersionedPlan.version", "DESC")
.limit(1)
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "inspectionVersionedPlan", err);
});
}
/**
* @description get inspectionVersionedPlan by id
* @returns {Promise<inspectionVersionedPlan>}

View file

@ -30,16 +30,3 @@ export type DamageReportViewModel = {
reportedBy: string;
maintenance?: MaintenanceViewModel;
} & DamageReportAssigned;
export interface CreateDamageReportViewModel {
description: string;
reportedBy: string;
affectedId: string;
affected: "equipment" | "vehicle" | "wearable";
}
export interface UpdateDamageReportViewModel {
id: string;
status: string;
done: boolean;
}

View file

@ -10,20 +10,3 @@ export interface EquipmentViewModel {
equipmentTypeId: string;
equipmentType: EquipmentTypeViewModel;
}
export interface CreateEquipmentViewModel {
code?: string;
name: string;
location: string;
commissioned: Date;
equipmentTypeId: string;
}
export interface UpdateEquipmentViewModel {
id: string;
code?: string;
name: string;
location: string;
commissioned: Date;
decommissioned?: Date;
}

View file

@ -3,14 +3,3 @@ export interface EquipmentTypeViewModel {
type: string;
description: string;
}
export interface CreateEquipmentTypeViewModel {
type: string;
description: string;
}
export interface UpdateEquipmentTypeViewModel {
id: string;
type: string;
description: string;
}

View file

@ -40,18 +40,3 @@ export interface InspectionPointViewModel {
max?: number;
sort: number;
}
export interface CreateInspectionPlanViewModel {
title: string;
inspectionInterval: PlanTimeDefinition;
remindTime: PlanTimeDefinition;
relatedId: string;
assigned: "vehicle" | "equipment";
}
export interface UpdateInspectionPlanViewModel {
id: string;
title: string;
inspectionInterval: PlanTimeDefinition;
remindTime?: PlanTimeDefinition;
}

View file

@ -28,16 +28,3 @@ export type MaintenanceViewModel = {
description: string;
reports: DamageReportViewModel[];
} & MaintenanceAssigned;
export interface CreateMaintenanceViewModel {
description: string;
reportedBy: string;
affectedId: string;
affected: "equipment" | "vehicle" | "wearable";
}
export interface UpdateMaintenanceViewModel {
id: string;
status: string;
done: boolean;
}

View file

@ -10,20 +10,3 @@ export interface VehicleViewModel {
vehicleTypeId: string;
vehicleType: VehicleTypeViewModel;
}
export interface CreateVehicleViewModel {
code?: string;
name: string;
location: string;
commissioned: Date;
vehicleTypeId: string;
}
export interface UpdateVehicleViewModel {
id: string;
code?: string;
name: string;
location: string;
commissioned: Date;
decommissioned?: Date;
}

View file

@ -3,14 +3,3 @@ export interface VehicleTypeViewModel {
type: string;
description: string;
}
export interface CreateVehicleTypeViewModel {
type: string;
description: string;
}
export interface UpdateVehicleTypeViewModel {
id: string;
type: string;
description: string;
}

View file

@ -13,22 +13,3 @@ export interface WearableViewModel {
wearableTypeId: string;
wearableType: WearableTypeViewModel;
}
export interface CreateWearableViewModel {
code?: string;
name: string;
wearerId?: string;
location?: string;
commissioned: Date;
wearableTypeId: string;
}
export interface UpdateWearableViewModel {
id: string;
code?: string;
name: string;
location?: string;
commissioned: Date;
decommissioned?: Date;
wearerId?: string;
}

View file

@ -3,14 +3,3 @@ export interface WearableTypeViewModel {
type: string;
description: string;
}
export interface CreateWearableTypeViewModel {
type: string;
description: string;
}
export interface UpdateWearableTypeViewModel {
id: string;
type: string;
description: string;
}