command Handlers and schema update
This commit is contained in:
parent
0f6401953f
commit
7883bb7d7f
42 changed files with 1076 additions and 159 deletions
17
src/command/unit/inspection/inspectionCommand.ts
Normal file
17
src/command/unit/inspection/inspectionCommand.ts
Normal 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;
|
||||
}
|
76
src/command/unit/inspection/inspectionCommandHandler.ts
Normal file
76
src/command/unit/inspection/inspectionCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
20
src/command/unit/inspection/inspectionPlanCommand.ts
Normal file
20
src/command/unit/inspection/inspectionPlanCommand.ts
Normal 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;
|
||||
}
|
76
src/command/unit/inspection/inspectionPlanCommandHandler.ts
Normal file
76
src/command/unit/inspection/inspectionPlanCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
11
src/command/unit/inspection/inspectionPointCommand.ts
Normal file
11
src/command/unit/inspection/inspectionPointCommand.ts
Normal 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;
|
||||
}
|
34
src/command/unit/inspection/inspectionPointCommandHandler.ts
Normal file
34
src/command/unit/inspection/inspectionPointCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
export interface CreateInspectionPointResultCommand {
|
||||
inspectionId: string;
|
||||
inspectionPointId: string;
|
||||
value: string;
|
||||
}
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export interface CreateInspectionVersionedPlanCommand {
|
||||
inspectionPlanId: string;
|
||||
}
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue