extend wearable and enable maintenance
This commit is contained in:
parent
aeb1ccbc42
commit
b8b2186c58
20 changed files with 457 additions and 93 deletions
|
@ -34,13 +34,20 @@ export async function getAllDamageReportsByStatus(req: Request, res: Response):
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllDamageReportsForRelated(req: Request, res: Response): Promise<any> {
|
||||
let relation = req.params.related as "vehicle" | "equipment";
|
||||
let relation = req.params.related as "vehicle" | "equipment" | "wearable";
|
||||
let relationId = req.params.relatedId as string;
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let noLimit = req.query.noLimit === "true";
|
||||
|
||||
let where = relation === "equipment" ? { equipmentId: relationId } : { vehicleId: relationId };
|
||||
let where;
|
||||
if (relation == "equipment") {
|
||||
where = { equipmentId: relationId };
|
||||
} else if (relation == "vehicle") {
|
||||
where = { vehicleId: relationId };
|
||||
} else {
|
||||
where = { wearableId: relationId };
|
||||
}
|
||||
let [damageReports, total] = await DamageReportService.getAllForRelated(where, { offset, count, noLimit });
|
||||
|
||||
res.json({
|
||||
|
|
|
@ -16,13 +16,20 @@ import BadRequestException from "../../../exceptions/badRequestException";
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllInspectionsForRelated(req: Request, res: Response): Promise<any> {
|
||||
let relation = req.params.related as "vehicle" | "equipment";
|
||||
let relation = req.params.related as "vehicle" | "equipment" | "wearable";
|
||||
let relationId = req.params.relatedId as string;
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let noLimit = req.query.noLimit === "true";
|
||||
|
||||
let where = relation === "equipment" ? { equipmentId: relationId } : { vehicleId: relationId };
|
||||
let where;
|
||||
if (relation == "equipment") {
|
||||
where = { equipmentId: relationId };
|
||||
} else if (relation == "vehicle") {
|
||||
where = { vehicleId: relationId };
|
||||
} else {
|
||||
where = { wearableId: relationId };
|
||||
}
|
||||
let [inspections, total] = await InspectionService.getAllForRelated(where, { offset, count, noLimit });
|
||||
|
||||
res.json({
|
||||
|
@ -59,8 +66,8 @@ export async function createInspection(req: Request, res: Response): Promise<any
|
|||
const assigned = req.body.assigned;
|
||||
const nextInspection = req.body.nextInspection || null;
|
||||
|
||||
if (assigned != "equipment" && assigned != "vehicle")
|
||||
throw new BadRequestException("set assigned to equipment or vehicle");
|
||||
if (assigned != "equipment" && assigned != "vehicle" && assigned != "wearable")
|
||||
throw new BadRequestException("set assigned to equipment or vehicle or wearable");
|
||||
|
||||
let createInspection: CreateInspectionCommand = {
|
||||
context,
|
||||
|
|
|
@ -46,7 +46,7 @@ export async function getAllInspectionPlans(req: Request, res: Response): Promis
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllInspectionPlansForRelated(req: Request, res: Response): Promise<any> {
|
||||
let relation = req.params.related as "vehicle" | "equipment";
|
||||
let relation = req.params.related as "vehicle" | "equipment" | "wearable";
|
||||
let relationId = req.params.relatedId as string;
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
|
@ -54,7 +54,14 @@ export async function getAllInspectionPlansForRelated(req: Request, res: Respons
|
|||
let noLimit = req.query.noLimit === "true";
|
||||
let ids = ((req.query.ids ?? "") as string).split(",").filter((i) => i);
|
||||
|
||||
let where = relation === "equipment" ? { equipmentTypeId: relationId } : { vehicleTypeId: relationId };
|
||||
let where;
|
||||
if (relation == "equipment") {
|
||||
where = { equipmentTypeId: relationId };
|
||||
} else if (relation == "vehicle") {
|
||||
where = { vehicleTypeId: relationId };
|
||||
} else {
|
||||
where = { wearableTypeId: relationId };
|
||||
}
|
||||
let [inspectionPlans, total] = await InspectionPlanService.getAllForRelated(where, {
|
||||
offset,
|
||||
count,
|
||||
|
@ -100,8 +107,8 @@ export async function createInspectionPlan(req: Request, res: Response): Promise
|
|||
TypeTester.testPlanTimeDefinition(inspectionInterval, "inspectionInterval", true);
|
||||
TypeTester.testPlanTimeDefinition(remindTime, "remindTime", true);
|
||||
|
||||
if (assigned != "equipment" && assigned != "vehicle")
|
||||
throw new BadRequestException("set assigned to equipment or vehicle");
|
||||
if (assigned != "equipment" && assigned != "vehicle" && assigned != "wearable")
|
||||
throw new BadRequestException("set assigned to equipment or vehicle or wearable");
|
||||
|
||||
let createInspectionPlan: CreateInspectionPlanCommand = {
|
||||
title,
|
||||
|
|
119
src/controller/admin/unit/maintenanceController.ts
Normal file
119
src/controller/admin/unit/maintenanceController.ts
Normal file
|
@ -0,0 +1,119 @@
|
|||
import { Request, Response } from "express";
|
||||
import MaintenanceService from "../../../service/unit/maintenanceService";
|
||||
import MaintenanceFactory from "../../../factory/admin/unit/maintenance";
|
||||
import { CreateMaintenanceCommand, UpdateMaintenanceCommand } from "../../../command/unit/maintenanceCommand";
|
||||
import MaintenanceCommandHandler from "../../../command/unit/maintenanceCommandHandler";
|
||||
import BadRequestException from "../../../exceptions/badRequestException";
|
||||
|
||||
/**
|
||||
* @description get all maintenances by status
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllMaintenancesByStatus(req: Request, res: Response): Promise<any> {
|
||||
let done = req.query.done === "true";
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let noLimit = req.query.noLimit === "true";
|
||||
|
||||
let [maintenances, total] = await MaintenanceService.getAll(done, { offset, count, noLimit });
|
||||
|
||||
res.json({
|
||||
maintenances: MaintenanceFactory.mapToBase(maintenances),
|
||||
total: total,
|
||||
offset: offset,
|
||||
count: count,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get all maintenances for related id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllMaintenancesForRelated(req: Request, res: Response): Promise<any> {
|
||||
let relation = req.params.related as "vehicle" | "equipment" | "wearable";
|
||||
let relationId = req.params.relatedId as string;
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let noLimit = req.query.noLimit === "true";
|
||||
|
||||
let where;
|
||||
if (relation == "equipment") {
|
||||
where = { equipmentId: relationId };
|
||||
} else if (relation == "vehicle") {
|
||||
where = { vehicleId: relationId };
|
||||
} else {
|
||||
where = { wearableId: relationId };
|
||||
}
|
||||
let [maintenances, total] = await MaintenanceService.getAllForRelated(where, { offset, count, noLimit });
|
||||
|
||||
res.json({
|
||||
maintenances: MaintenanceFactory.mapToBase(maintenances),
|
||||
total: total,
|
||||
offset: offset,
|
||||
count: count,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get maintenance by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getMaintenanceById(req: Request, res: Response): Promise<any> {
|
||||
const maintenanceId = req.params.id;
|
||||
let maintenance = await MaintenanceService.getById(maintenanceId);
|
||||
|
||||
res.json(MaintenanceFactory.mapToSingle(maintenance));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create maintenance
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createMaintenance(req: Request, res: Response): Promise<any> {
|
||||
const description = req.body.description;
|
||||
const affectedId = req.body.affectedId;
|
||||
const affected = req.body.affected;
|
||||
|
||||
if (affected != "equipment" && affected != "vehicle" && affected != "wearable")
|
||||
throw new BadRequestException("set assigned to equipment or vehicle or wearable");
|
||||
|
||||
let createMaintenance: CreateMaintenanceCommand = {
|
||||
description,
|
||||
affectedId,
|
||||
affected,
|
||||
};
|
||||
let maintenanceId = await MaintenanceCommandHandler.create(createMaintenance);
|
||||
|
||||
res.status(200).send(maintenanceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update maintenance by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateMaintenanceById(req: Request, res: Response): Promise<any> {
|
||||
const maintenanceId = req.params.id;
|
||||
const description = req.body.description;
|
||||
const status = req.body.status;
|
||||
const done = req.body.done;
|
||||
|
||||
let updateMaintenance: UpdateMaintenanceCommand = {
|
||||
id: maintenanceId,
|
||||
description,
|
||||
status,
|
||||
done,
|
||||
};
|
||||
await MaintenanceCommandHandler.update(updateMaintenance);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
|
@ -5,6 +5,7 @@ import { getTypeByORM } from "../../../migrations/ormHelper";
|
|||
import { vehicle } from "../vehicle/vehicle";
|
||||
import { equipment } from "../equipment/equipment";
|
||||
import { inspectionPointResult } from "./inspectionPointResult";
|
||||
import { wearable } from "../wearable/wearable";
|
||||
|
||||
@Entity()
|
||||
export class inspection {
|
||||
|
@ -35,6 +36,9 @@ export class inspection {
|
|||
@Column({ nullable: true, default: null })
|
||||
vehicleId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
wearableId?: string;
|
||||
|
||||
@ManyToOne(() => inspectionPlan, {
|
||||
nullable: false,
|
||||
onDelete: "RESTRICT",
|
||||
|
@ -63,6 +67,13 @@ export class inspection {
|
|||
})
|
||||
vehicle: vehicle;
|
||||
|
||||
@ManyToOne(() => wearable, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
wearable: wearable;
|
||||
|
||||
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection)
|
||||
pointResults: inspectionPointResult[];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { PlanTimeDefinition } from "../../../viewmodel/admin/unit/inspection/ins
|
|||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
import { equipmentType } from "../equipment/equipmentType";
|
||||
import { vehicleType } from "../vehicle/vehicleType";
|
||||
import { wearableType } from "../wearable/wearableType";
|
||||
|
||||
@Entity()
|
||||
export class inspectionPlan {
|
||||
|
@ -27,6 +28,9 @@ export class inspectionPlan {
|
|||
@Column({ nullable: true, default: null })
|
||||
vehicleTypeId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
wearableTypeId?: string;
|
||||
|
||||
@ManyToOne(() => equipmentType, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
|
@ -41,6 +45,13 @@ export class inspectionPlan {
|
|||
})
|
||||
vehicleType?: vehicleType;
|
||||
|
||||
@ManyToOne(() => wearableType, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
wearableType?: wearableType;
|
||||
|
||||
@OneToMany(() => inspectionVersionedPlan, (ivp) => ivp.inspectionPlan, {
|
||||
cascade: ["insert"],
|
||||
})
|
||||
|
|
|
@ -47,4 +47,7 @@ export class wearable {
|
|||
|
||||
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.wearable)
|
||||
inspections: inspection[];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { wearable as wearable } from "./wearable";
|
||||
import { inspectionPlan } from "../inspection/inspectionPlan";
|
||||
|
||||
@Entity()
|
||||
export class wearableType {
|
||||
|
@ -14,4 +15,7 @@ export class wearableType {
|
|||
|
||||
@OneToMany(() => wearable, (e) => e.wearableType, { cascade: ["insert"] })
|
||||
wearable: wearable[];
|
||||
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.wearableType)
|
||||
inspectionPlans: inspectionPlan[];
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { inspection } from "../../../../entity/unit/inspection/inspection";
|
||||
import { InspectionViewModel } from "../../../../viewmodel/admin/unit/inspection/inspection.models";
|
||||
import { InspectionRelated, InspectionViewModel } from "../../../../viewmodel/admin/unit/inspection/inspection.models";
|
||||
import EquipmentFactory from "../equipment/equipment";
|
||||
import VehicleFactory from "../vehicle/vehicle";
|
||||
import WearableFactory from "../wearable/wearable";
|
||||
import InspectionPlanFactory from "./inspectionPlan";
|
||||
import InspectionPointResultFactory from "./inspectionPointResult";
|
||||
import InspectionVersionedPlanFactory from "./inspectionVersionedPlan";
|
||||
|
@ -13,6 +14,27 @@ export default abstract class InspectionFactory {
|
|||
* @returns {InspectionViewModel}
|
||||
*/
|
||||
public static mapToSingle(record: inspection): InspectionViewModel {
|
||||
let related: InspectionRelated;
|
||||
if (record?.equipmentId) {
|
||||
related = {
|
||||
relatedId: record.equipmentId,
|
||||
assigned: "equipment",
|
||||
related: EquipmentFactory.mapToSingle(record.equipment),
|
||||
};
|
||||
} else if (record?.vehicleId) {
|
||||
related = {
|
||||
relatedId: record.vehicleId,
|
||||
assigned: "vehicle",
|
||||
related: VehicleFactory.mapToSingle(record.vehicle),
|
||||
};
|
||||
} else {
|
||||
related = {
|
||||
relatedId: record.wearableId,
|
||||
assigned: "wearable",
|
||||
related: WearableFactory.mapToSingle(record.wearable),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
inspectionPlanId: record.inspectionPlanId,
|
||||
|
@ -25,17 +47,7 @@ export default abstract class InspectionFactory {
|
|||
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),
|
||||
}),
|
||||
...related,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import { inspectionPlan } from "../../../../entity/unit/inspection/inspectionPlan";
|
||||
import { InspectionPlanViewModel } from "../../../../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
||||
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 {
|
||||
|
@ -13,6 +17,27 @@ export default abstract class InspectionPlanFactory {
|
|||
* @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,
|
||||
|
@ -23,17 +48,7 @@ export default abstract class InspectionPlanFactory {
|
|||
inspectionPoints: record.latestVersionedPlan
|
||||
? InspectionPointFactory.mapToBase(record.latestVersionedPlan.inspectionPoints)
|
||||
: [],
|
||||
...(record.equipmentTypeId
|
||||
? {
|
||||
relatedId: record.equipmentTypeId,
|
||||
assigned: "equipment",
|
||||
related: EquipmentTypeFactory.mapToSingle(record.equipmentType),
|
||||
}
|
||||
: {
|
||||
relatedId: record.vehicleTypeId,
|
||||
assigned: "vehicle",
|
||||
related: VehicleTypeFactory.mapToSingle(record.vehicleType),
|
||||
}),
|
||||
...related,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import wearableType from "./unit/wearableType";
|
|||
import inspection from "./unit/inspection";
|
||||
import inspectionPlan from "./unit/inspectionPlan";
|
||||
import damageReport from "./unit/damageReport";
|
||||
import maintenance from "./unit/maintenance";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
|
@ -189,39 +190,75 @@ router.use(
|
|||
router.use("/setting", PermissionHelper.passCheckMiddleware("read", "management", "setting"), setting);
|
||||
|
||||
/** unit */
|
||||
router.use("/equipment", PermissionHelper.passCheckMiddleware("read", "unit", "equipment"), equipment);
|
||||
router.use(
|
||||
"/equipment",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
]),
|
||||
equipment
|
||||
);
|
||||
router.use(
|
||||
"/equipmenttype",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment_type" },
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
]),
|
||||
equipmentType
|
||||
);
|
||||
router.use("/vehicle", PermissionHelper.passCheckMiddleware("read", "unit", "vehicle"), vehicle);
|
||||
router.use(
|
||||
"/vehicle",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
]),
|
||||
vehicle
|
||||
);
|
||||
router.use(
|
||||
"/vehicletype",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle_type" },
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
]),
|
||||
vehicleType
|
||||
);
|
||||
router.use("/wearable", PermissionHelper.passCheckMiddleware("read", "unit", "wearable"), wearable);
|
||||
router.use(
|
||||
"/wearable",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
]),
|
||||
wearable
|
||||
);
|
||||
router.use(
|
||||
"/wearabletype",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable_type" },
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
]),
|
||||
wearableType
|
||||
);
|
||||
router.use("/inspection", PermissionHelper.passCheckMiddleware("read", "unit", "inspection"), inspection);
|
||||
router.use(
|
||||
"/inspection",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection" },
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment" },
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle" },
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable" },
|
||||
]),
|
||||
inspection
|
||||
);
|
||||
router.use(
|
||||
"/inspectionplan",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
|
||||
{ requiredPermission: "read", section: "unit", module: "inspection" },
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment_type" },
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle_type" },
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable_type" },
|
||||
]),
|
||||
inspectionPlan
|
||||
);
|
||||
|
@ -229,11 +266,22 @@ router.use(
|
|||
"/damagereport",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "damage_report" },
|
||||
{ requiredPermission: "read", section: "unit", module: "maintenance" },
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment" },
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle" },
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable" },
|
||||
]),
|
||||
damageReport
|
||||
);
|
||||
router.use(
|
||||
"/mainenance",
|
||||
PermissionHelper.passCheckSomeMiddleware([
|
||||
{ requiredPermission: "read", section: "unit", module: "maintenance" },
|
||||
{ requiredPermission: "read", section: "unit", module: "equipment" },
|
||||
{ requiredPermission: "read", section: "unit", module: "vehicle" },
|
||||
{ requiredPermission: "read", section: "unit", module: "wearable" },
|
||||
]),
|
||||
maintenance
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -10,15 +10,20 @@ import {
|
|||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
router.get(["/vehicle/:relatedId", "/equipment/:relatedId"], async (req: Request, res: Response) => {
|
||||
if (req.path.startsWith("/vehicle")) {
|
||||
req.params.related = "vehicle";
|
||||
} else {
|
||||
req.params.related = "equipment";
|
||||
}
|
||||
router.get(
|
||||
["/vehicle/:relatedId", "/equipment/:relatedId", "/wearable/:relatedId"],
|
||||
async (req: Request, res: Response) => {
|
||||
if (req.path.startsWith("/vehicle")) {
|
||||
req.params.related = "vehicle";
|
||||
} else if (req.path.startsWith("/equipment")) {
|
||||
req.params.related = "equipment";
|
||||
} else {
|
||||
req.params.related = "wearable";
|
||||
}
|
||||
|
||||
await getAllInspectionsForRelated(req, res);
|
||||
});
|
||||
await getAllInspectionsForRelated(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/:id", async (req: Request, res: Response) => {
|
||||
await getInspectionById(req, res);
|
||||
|
|
|
@ -15,15 +15,20 @@ router.get("/", async (req: Request, res: Response) => {
|
|||
await getAllInspectionPlans(req, res);
|
||||
});
|
||||
|
||||
router.get(["/vehicle/:relatedId", "/equipment/:relatedId"], async (req: Request, res: Response) => {
|
||||
if (req.path.startsWith("/vehicle")) {
|
||||
req.params.related = "vehicle";
|
||||
} else {
|
||||
req.params.related = "equipment";
|
||||
}
|
||||
router.get(
|
||||
["/vehicle/:relatedId", "/equipment/:relatedId", "/wearable/:relatedId"],
|
||||
async (req: Request, res: Response) => {
|
||||
if (req.path.startsWith("/vehicle")) {
|
||||
req.params.related = "vehicle";
|
||||
} else if (req.path.startsWith("/equipment")) {
|
||||
req.params.related = "equipment";
|
||||
} else {
|
||||
req.params.related = "wearable";
|
||||
}
|
||||
|
||||
await getAllInspectionPlansForRelated(req, res);
|
||||
});
|
||||
await getAllInspectionPlansForRelated(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/:id", async (req: Request, res: Response) => {
|
||||
await getInspectionPlanById(req, res);
|
||||
|
|
43
src/routes/admin/unit/maintenance.ts
Normal file
43
src/routes/admin/unit/maintenance.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import express, { Request, Response } from "express";
|
||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||
import {
|
||||
getAllMaintenancesByStatus,
|
||||
getAllMaintenancesForRelated,
|
||||
getMaintenanceById,
|
||||
updateMaintenanceById,
|
||||
} from "../../../controller/admin/unit/maintenanceController";
|
||||
|
||||
var router = express.Router({ mergeParams: true });
|
||||
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
await getAllMaintenancesByStatus(req, res);
|
||||
});
|
||||
|
||||
router.get(
|
||||
["/vehicle/:relatedId", "/equipment/:relatedId", "/wearable/:relatedId"],
|
||||
async (req: Request, res: Response) => {
|
||||
if (req.path.startsWith("/vehicle")) {
|
||||
req.params.related = "vehicle";
|
||||
} else if (req.path.startsWith("/equipment")) {
|
||||
req.params.related = "equipment";
|
||||
} else {
|
||||
req.params.related = "wearable";
|
||||
}
|
||||
|
||||
await getAllMaintenancesForRelated(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/:id", async (req: Request, res: Response) => {
|
||||
await getMaintenanceById(req, res);
|
||||
});
|
||||
|
||||
router.patch(
|
||||
"/:id",
|
||||
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
|
||||
async (req: Request, res: Response) => {
|
||||
await updateMaintenanceById(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
export default router;
|
|
@ -16,7 +16,8 @@ export default abstract class InspectionPlanService {
|
|||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipmentType", "equipmentType")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicleType", "vehicleType");
|
||||
.leftJoinAndSelect("inspectionPlan.vehicleType", "vehicleType")
|
||||
.leftJoinAndSelect("inspectionPlan.wearableType", "wearableType");
|
||||
|
||||
/**
|
||||
* @description get all inspectionPlans for related
|
||||
|
@ -67,7 +68,7 @@ export default abstract class InspectionPlanService {
|
|||
* @returns {Promise<[Array<inspectionPlan>, number]>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentTypeId: string } | { vehicleTypeId: string },
|
||||
where: { equipmentTypeId: string } | { vehicleTypeId: string } | { wearableTypeId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
|
|
|
@ -13,14 +13,15 @@ export default abstract class InspectionService {
|
|||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle");
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("inspection.wearable", "wearable");
|
||||
|
||||
/**
|
||||
* @description get all inspections for related
|
||||
* @returns {Promise<Array<inspection>>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string },
|
||||
where: { equipmentId: string } | { vehicleId: string } | { wearableId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
|
|
|
@ -3,20 +3,72 @@ import { maintenance } from "../../entity/unit/maintenance";
|
|||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class MaintenanceService {
|
||||
/**
|
||||
* @description get all maintenances
|
||||
* @returns {Promise<Array<maintenance>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<maintenance>> {
|
||||
return await dataSource
|
||||
private static query = () =>
|
||||
dataSource
|
||||
.getRepository(maintenance)
|
||||
.createQueryBuilder("maintenance")
|
||||
.leftJoinAndSelect("maintenance.equipment", "equipment")
|
||||
.leftJoinAndSelect("maintenance.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("maintenance.wearable", "wearable")
|
||||
.leftJoinAndSelect("maintenance.reports", "reports")
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.leftJoinAndSelect("maintenance.reports", "reports");
|
||||
|
||||
/**
|
||||
* @description get all maintenances
|
||||
* @returns {Promise<[Array<maintenance>, number]>}
|
||||
*/
|
||||
static async getAll(
|
||||
done = false,
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}
|
||||
): Promise<[Array<maintenance>, number]> {
|
||||
let query = this.query().where({ done });
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("maintenance.type", "ASC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "maintenance", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get all maintenances By related
|
||||
* @returns {Promise<[Array<maintenance>, number]>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string } | { wearableId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}
|
||||
): Promise<[Array<maintenance>, number]> {
|
||||
let query = this.query().where(where);
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("maintenance.createdAt", "ASC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
@ -30,13 +82,7 @@ export default abstract class MaintenanceService {
|
|||
* @returns {Promise<maintenance>}
|
||||
*/
|
||||
static async getById(id: string): Promise<maintenance> {
|
||||
return await dataSource
|
||||
.getRepository(maintenance)
|
||||
.createQueryBuilder("maintenance")
|
||||
.leftJoinAndSelect("maintenance.equipment", "equipment")
|
||||
.leftJoinAndSelect("maintenance.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("maintenance.wearable", "wearable")
|
||||
.leftJoinAndSelect("maintenance.reports", "reports")
|
||||
return await this.query()
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -21,6 +21,7 @@ export type PermissionModule =
|
|||
| "respiratory_wearer"
|
||||
| "respiratory_mission"
|
||||
| "damage_report"
|
||||
| "maintenance"
|
||||
// configuration
|
||||
| "qualification"
|
||||
| "award"
|
||||
|
@ -95,6 +96,7 @@ export const permissionModules: Array<PermissionModule> = [
|
|||
"respiratory_wearer",
|
||||
"respiratory_mission",
|
||||
"damage_report",
|
||||
"maintenance",
|
||||
// configuration
|
||||
"qualification",
|
||||
"award",
|
||||
|
@ -131,6 +133,7 @@ export const sectionsAndModules: SectionsAndModulesObject = {
|
|||
"respiratory_wearer",
|
||||
"respiratory_mission",
|
||||
"damage_report",
|
||||
"maintenance",
|
||||
],
|
||||
configuration: [
|
||||
"qualification",
|
||||
|
|
|
@ -5,6 +5,24 @@ import type {
|
|||
InspectionVersionedPlanViewModel,
|
||||
} from "./inspectionPlan.models";
|
||||
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
||||
import { WearableViewModel } from "../wearable/wearable.models";
|
||||
|
||||
export type InspectionRelated = {
|
||||
relatedId: string;
|
||||
} & (
|
||||
| {
|
||||
assigned: "equipment";
|
||||
related: EquipmentViewModel;
|
||||
}
|
||||
| {
|
||||
assigned: "vehicle";
|
||||
related: VehicleViewModel;
|
||||
}
|
||||
| {
|
||||
assigned: "wearable";
|
||||
related: WearableViewModel;
|
||||
}
|
||||
);
|
||||
|
||||
export type InspectionViewModel = {
|
||||
id: string;
|
||||
|
@ -18,17 +36,7 @@ export type InspectionViewModel = {
|
|||
isOpen: boolean;
|
||||
nextInspection?: Date;
|
||||
checks: Array<InspectionPointResultViewModel>;
|
||||
relatedId: string;
|
||||
} & (
|
||||
| {
|
||||
assigned: "equipment";
|
||||
related: EquipmentViewModel;
|
||||
}
|
||||
| {
|
||||
assigned: "vehicle";
|
||||
related: VehicleViewModel;
|
||||
}
|
||||
);
|
||||
} & InspectionRelated;
|
||||
|
||||
export interface InspectionPointResultViewModel {
|
||||
inspectionId: string;
|
||||
|
|
|
@ -3,17 +3,11 @@ import type { EquipmentViewModel } from "../equipment/equipment.models";
|
|||
import { EquipmentTypeViewModel } from "../equipment/equipmentType.models";
|
||||
import type { VehicleViewModel } from "../vehicle/vehicle.models";
|
||||
import { VehicleTypeViewModel } from "../vehicle/vehicleType.models";
|
||||
import { WearableTypeViewModel } from "../wearable/wearableType.models";
|
||||
|
||||
export type PlanTimeDefinition = `${number}-${"d" | "m" | "y"}` | `${number}/${number | "*"}`;
|
||||
|
||||
export type InspectionPlanViewModel = {
|
||||
id: string;
|
||||
title: string;
|
||||
inspectionInterval: PlanTimeDefinition;
|
||||
remindTime: PlanTimeDefinition;
|
||||
version: number;
|
||||
created: Date;
|
||||
inspectionPoints: InspectionPointViewModel[];
|
||||
export type InspectionPlanRelated = {
|
||||
relatedId: string;
|
||||
} & (
|
||||
| {
|
||||
|
@ -24,8 +18,22 @@ export type InspectionPlanViewModel = {
|
|||
assigned: "vehicle";
|
||||
related: VehicleTypeViewModel;
|
||||
}
|
||||
| {
|
||||
assigned: "wearable";
|
||||
related: WearableTypeViewModel;
|
||||
}
|
||||
);
|
||||
|
||||
export type InspectionPlanViewModel = {
|
||||
id: string;
|
||||
title: string;
|
||||
inspectionInterval: PlanTimeDefinition;
|
||||
remindTime: PlanTimeDefinition;
|
||||
version: number;
|
||||
created: Date;
|
||||
inspectionPoints: InspectionPointViewModel[];
|
||||
} & InspectionPlanRelated;
|
||||
|
||||
export interface InspectionVersionedPlanViewModel {
|
||||
id: string;
|
||||
version: number;
|
||||
|
|
Loading…
Add table
Reference in a new issue