diff --git a/src/command/unit/inspection/inspectionPlanCommandHandler.ts b/src/command/unit/inspection/inspectionPlanCommandHandler.ts index cf48ef7..179f8a7 100644 --- a/src/command/unit/inspection/inspectionPlanCommandHandler.ts +++ b/src/command/unit/inspection/inspectionPlanCommandHandler.ts @@ -22,8 +22,8 @@ export default abstract class InspectionPlanCommandHandler { title: createInspectionPlan.title, inspectionInterval: createInspectionPlan.inspectionInterval, remindTime: createInspectionPlan.remindTime, - equipmentId: createInspectionPlan.assigned == "equipment" ? createInspectionPlan.relatedId : null, - vehicleId: createInspectionPlan.assigned == "vehicle" ? createInspectionPlan.relatedId : null, + equipmentTypeId: createInspectionPlan.assigned == "equipment" ? createInspectionPlan.relatedId : null, + vehicleTypeId: createInspectionPlan.assigned == "vehicle" ? createInspectionPlan.relatedId : null, }) .execute() .then((result) => { diff --git a/src/controller/admin/unit/damageReportController.ts b/src/controller/admin/unit/damageReportController.ts new file mode 100644 index 0000000..9576ec9 --- /dev/null +++ b/src/controller/admin/unit/damageReportController.ts @@ -0,0 +1,113 @@ +import { Request, Response } from "express"; +import DamageReportService from "../../../service/unit/damageReportService"; +import DamageReportFactory from "../../../factory/admin/unit/damageReport"; +import { CreateDamageReportCommand, UpdateDamageReportCommand } from "../../../command/unit/damageReportCommand"; +import DamageReportCommandHandler from "../../../command/unit/damageReportCommandHandler"; +import BadRequestException from "../../../exceptions/badRequestException"; + +/** + * @description get all damageReports by status + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllDamageReportsByStatus(req: Request, res: Response): Promise { + 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 [damageReports, total] = await DamageReportService.getAll(done, { offset, count, noLimit }); + + res.json({ + damageReports: DamageReportFactory.mapToBase(damageReports), + total: total, + offset: offset, + count: count, + }); +} + +/** + * @description get all damageReports for related id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllDamageReportsForRelated(req: Request, res: Response): Promise { + let relation = req.params.related as "vehicle" | "equipment"; + 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 [damageReports, total] = await DamageReportService.getAllForRelated(where, { offset, count, noLimit }); + + res.json({ + damageReports: DamageReportFactory.mapToBase(damageReports), + total: total, + offset: offset, + count: count, + }); +} + +/** + * @description get damageReport by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getDamageReportById(req: Request, res: Response): Promise { + const damageReportId = req.params.id; + let damageReport = await DamageReportService.getById(damageReportId); + + res.json(DamageReportFactory.mapToSingle(damageReport)); +} + +/** + * @description create damageReport + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createDamageReport(req: Request, res: Response): Promise { + const description = req.body.description; + const reportedBy = req.body.reportedBy; + 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 createDamageReport: CreateDamageReportCommand = { + description, + reportedBy, + imageCount: 0, + affectedId, + affected, + }; + let damageReportId = await DamageReportCommandHandler.create(createDamageReport); + + res.status(200).send(damageReportId); +} + +/** + * @description update damageReport by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateDamageReportById(req: Request, res: Response): Promise { + const damageReportId = req.params.id; + const status = req.body.status; + const done = req.body.done; + + let updateDamageReport: UpdateDamageReportCommand = { + id: damageReportId, + status, + done, + }; + await DamageReportCommandHandler.update(updateDamageReport); + + res.sendStatus(204); +} diff --git a/src/controller/admin/unit/equipmentController.ts b/src/controller/admin/unit/equipmentController.ts index 8d7e200..caee218 100644 --- a/src/controller/admin/unit/equipmentController.ts +++ b/src/controller/admin/unit/equipmentController.ts @@ -24,7 +24,7 @@ export async function getAllEquipments(req: Request, res: Response): Promise} */ export async function createEquipment(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const name = req.body.name; + const code = req.body.code || null; + const location = req.body.location; + const commissioned = req.body.commissioned; + const equipmentTypeId = req.body.equipmentTypeId; let createEquipment: CreateEquipmentCommand = { - name: "", - location: "", - commissioned: undefined, - equipmentTypeId: "", + code, + name, + location, + commissioned, + equipmentTypeId, }; let equipmentId = await EquipmentCommandHandler.create(createEquipment); @@ -91,13 +96,19 @@ export async function createEquipment(req: Request, res: Response): Promise */ export async function updateEquipmentById(req: Request, res: Response): Promise { const equipmentId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const name = req.body.name; + const code = req.body.code || null; + const location = req.body.location; + const commissioned = req.body.commissioned; + const decommissioned = req.body.decommissioned || null; let updateEquipment: UpdateEquipmentCommand = { id: equipmentId, - name: "", - location: "", - commissioned: undefined, + name, + code, + location, + commissioned, + decommissioned, }; await EquipmentCommandHandler.update(updateEquipment); diff --git a/src/controller/admin/unit/equipmentTypeController.ts b/src/controller/admin/unit/equipmentTypeController.ts index dce7b77..cfae069 100644 --- a/src/controller/admin/unit/equipmentTypeController.ts +++ b/src/controller/admin/unit/equipmentTypeController.ts @@ -19,12 +19,11 @@ export async function getAllEquipmentTypes(req: Request, res: Response): Promise let count = parseInt((req.query.count as string) ?? "25"); let search = (req.query.search as string) ?? ""; let noLimit = req.query.noLimit === "true"; - let ids = ((req.query.ids ?? "") as string).split(",").filter((i) => i); - let [equipmentTypes, total] = await EquipmentTypeService.getAll({ offset, count, search, noLimit, ids }); + let [equipmentTypes, total] = await EquipmentTypeService.getAll({ offset, count, search, noLimit }); res.json({ - equipmentTypes: equipmentTypes, + equipmentTypes: EquipmentTypeFactory.mapToBase(equipmentTypes), total: total, offset: offset, count: count, @@ -51,11 +50,12 @@ export async function getEquipmentTypeById(req: Request, res: Response): Promise * @returns {Promise<*>} */ export async function createEquipmentType(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const type = req.body.type; + const description = req.body.description; let createEquipmentType: CreateEquipmentTypeCommand = { - type: "", - description: "", + type, + description, }; let equipmentTypeId = await EquipmentTypeCommandHandler.create(createEquipmentType); @@ -70,12 +70,13 @@ export async function createEquipmentType(req: Request, res: Response): Promise< */ export async function updateEquipmentTypeById(req: Request, res: Response): Promise { const equipmentTypeId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const type = req.body.type; + const description = req.body.description; let updateEquipmentType: UpdateEquipmentTypeCommand = { id: equipmentTypeId, - type: "", - description: "", + type, + description, }; await EquipmentTypeCommandHandler.update(updateEquipmentType); diff --git a/src/controller/admin/unit/inspectionController.ts b/src/controller/admin/unit/inspectionController.ts index 8c4b782..2380bdf 100644 --- a/src/controller/admin/unit/inspectionController.ts +++ b/src/controller/admin/unit/inspectionController.ts @@ -7,6 +7,7 @@ import { UpdateInspectionCommand, } from "../../../command/unit/inspection/inspectionCommand"; import InspectionCommandHandler from "../../../command/unit/inspection/inspectionCommandHandler"; +import BadRequestException from "../../../exceptions/badRequestException"; /** * @description get all inspections for related id @@ -25,7 +26,7 @@ export async function getAllInspectionsForRelated(req: Request, res: Response): let [inspections, total] = await InspectionService.getAllForRelated(where, { offset, count, noLimit }); res.json({ - inspections: inspections, + inspections: InspectionFactory.mapToBase(inspections), total: total, offset: offset, count: count, @@ -52,13 +53,21 @@ export async function getInspectionById(req: Request, res: Response): Promise} */ export async function createInspection(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const context = req.body.context; + const inspectionPlanId = req.body.inspectionPlanId; + const relatedId = req.body.relatedId; + 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"); let createInspection: CreateInspectionCommand = { - context: "", - inspectionPlanId: "", - relatedId: "", - assigned: "equipment", + context, + nextInspection, + inspectionPlanId, + relatedId, + assigned, }; let inspectionId = await InspectionCommandHandler.create(createInspection); @@ -73,11 +82,13 @@ export async function createInspection(req: Request, res: Response): Promise { const inspectionId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const context = req.body.context; + const nextInspection = req.body.nextInspection || null; let updateInspection: UpdateInspectionCommand = { id: inspectionId, - context: "", + context, + nextInspection, }; await InspectionCommandHandler.update(updateInspection); diff --git a/src/controller/admin/unit/inspectionPlanController.ts b/src/controller/admin/unit/inspectionPlanController.ts index 358ac66..5089c82 100644 --- a/src/controller/admin/unit/inspectionPlanController.ts +++ b/src/controller/admin/unit/inspectionPlanController.ts @@ -7,6 +7,37 @@ import { UpdateInspectionPlanCommand, } from "../../../command/unit/inspection/inspectionPlanCommand"; import InspectionPlanCommandHandler from "../../../command/unit/inspection/inspectionPlanCommandHandler"; +import BadRequestException from "../../../exceptions/badRequestException"; +import TypeTester from "../../../helpers/typeTester"; + +/** + * @description get all inspectionPlans + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllInspectionPlans(req: Request, res: Response): Promise { + let offset = parseInt((req.query.offset as string) ?? "0"); + let count = parseInt((req.query.count as string) ?? "25"); + let search = (req.query.search as string) ?? ""; + let noLimit = req.query.noLimit === "true"; + let ids = ((req.query.ids ?? "") as string).split(",").filter((i) => i); + + let [inspectionPlans, total] = await InspectionPlanService.getAll({ + offset, + count, + search, + noLimit, + ids, + }); + + res.json({ + inspectionPlans: InspectionPlanFactory.mapToBase(inspectionPlans), + total: total, + offset: offset, + count: count, + }); +} /** * @description get all inspectionPlans @@ -23,7 +54,7 @@ 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" ? { equipmentId: relationId } : { vehicleId: relationId }; + let where = relation === "equipment" ? { equipmentTypeId: relationId } : { vehicleTypeId: relationId }; let [inspectionPlans, total] = await InspectionPlanService.getAllForRelated(where, { offset, count, @@ -60,14 +91,24 @@ export async function getInspectionPlanById(req: Request, res: Response): Promis * @returns {Promise<*>} */ export async function createInspectionPlan(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const title = req.body.title; + const inspectionInterval = req.body.inspectionInterval; + const remindTime = req.body.remindTime; + const relatedId = req.body.relatedId; + const assigned = req.body.assigned; + + TypeTester.testPlanTimeDefinition(inspectionInterval, "inspectionInterval", true); + TypeTester.testPlanTimeDefinition(remindTime, "remindTime", true); + + if (assigned != "equipment" && assigned != "vehicle") + throw new BadRequestException("set assigned to equipment or vehicle"); let createInspectionPlan: CreateInspectionPlanCommand = { - title: "", - inspectionInterval: "1-m", - remindTime: "1-m", - relatedId: "", - assigned: "equipment", + title, + inspectionInterval, + remindTime, + relatedId, + assigned, }; let inspectionPlanId = await InspectionPlanCommandHandler.create(createInspectionPlan); @@ -82,12 +123,18 @@ export async function createInspectionPlan(req: Request, res: Response): Promise */ export async function updateInspectionPlanById(req: Request, res: Response): Promise { const inspectionPlanId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const title = req.body.title; + const inspectionInterval = req.body.inspectionInterval; + const remindTime = req.body.remindTime; + + TypeTester.testPlanTimeDefinition(inspectionInterval, "inspectionInterval", true); + TypeTester.testPlanTimeDefinition(remindTime, "remindTime", true); let updateInspectionPlan: UpdateInspectionPlanCommand = { id: inspectionPlanId, - title: "", - inspectionInterval: "1-m", + title, + inspectionInterval, + remindTime, }; await InspectionPlanCommandHandler.update(updateInspectionPlan); diff --git a/src/controller/admin/unit/vehicleController.ts b/src/controller/admin/unit/vehicleController.ts index 02b3606..a54d2c1 100644 --- a/src/controller/admin/unit/vehicleController.ts +++ b/src/controller/admin/unit/vehicleController.ts @@ -24,7 +24,7 @@ export async function getAllVehicles(req: Request, res: Response): Promise let [vehicles, total] = await VehicleService.getAll({ offset, count, search, noLimit, ids }); res.json({ - vehicles: vehicles, + vehicles: VehicleFactory.mapToBase(vehicles), total: total, offset: offset, count: count, @@ -44,6 +44,25 @@ export async function getVehicleById(req: Request, res: Response): Promise res.json(VehicleFactory.mapToSingle(vehicle)); } +/** + * @description get vehicle by Ids + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getVehiclesByIds(req: Request, res: Response): Promise { + let ids = req.body.ids as Array; + + let [vehicles, total] = await VehicleService.getAll({ noLimit: true, ids }); + + res.json({ + vehicles: VehicleFactory.mapToBase(vehicles), + total: total, + offset: 0, + count: total, + }); +} + /** * @description create vehicle * @param req {Request} Express req object @@ -51,13 +70,18 @@ export async function getVehicleById(req: Request, res: Response): Promise * @returns {Promise<*>} */ export async function createVehicle(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const name = req.body.name; + const code = req.body.code || null; + const location = req.body.location; + const commissioned = req.body.commissioned; + const vehicleTypeId = req.body.vehicleTypeId; let createVehicle: CreateVehicleCommand = { - name: "", - location: "", - commissioned: undefined, - vehicleTypeId: "", + code, + name, + location, + commissioned, + vehicleTypeId, }; let vehicleId = await VehicleCommandHandler.create(createVehicle); @@ -72,13 +96,19 @@ export async function createVehicle(req: Request, res: Response): Promise { */ export async function updateVehicleById(req: Request, res: Response): Promise { const vehicleId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const name = req.body.name; + const code = req.body.code || null; + const location = req.body.location; + const commissioned = req.body.commissioned; + const decommissioned = req.body.decommissioned || null; let updateVehicle: UpdateVehicleCommand = { id: vehicleId, - name: "", - location: "", - commissioned: undefined, + code, + name, + location, + commissioned, + decommissioned, }; await VehicleCommandHandler.update(updateVehicle); diff --git a/src/controller/admin/unit/vehicleTypeController.ts b/src/controller/admin/unit/vehicleTypeController.ts index 7cf5552..b105ea1 100644 --- a/src/controller/admin/unit/vehicleTypeController.ts +++ b/src/controller/admin/unit/vehicleTypeController.ts @@ -19,12 +19,11 @@ export async function getAllVehicleTypes(req: Request, res: Response): Promise i); - let [vehicleTypes, total] = await VehicleTypeService.getAll({ offset, count, search, noLimit, ids }); + let [vehicleTypes, total] = await VehicleTypeService.getAll({ offset, count, search, noLimit }); res.json({ - vehicleTypes: vehicleTypes, + vehicleTypes: VehicleTypeFactory.mapToBase(vehicleTypes), total: total, offset: offset, count: count, @@ -51,11 +50,12 @@ export async function getVehicleTypeById(req: Request, res: Response): Promise} */ export async function createVehicleType(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const type = req.body.type; + const description = req.body.description; let createVehicleType: CreateVehicleTypeCommand = { - type: "", - description: "", + type, + description, }; let vehicleTypeId = await VehicleTypeCommandHandler.create(createVehicleType); @@ -70,12 +70,13 @@ export async function createVehicleType(req: Request, res: Response): Promise { const vehicleTypeId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const type = req.body.type; + const description = req.body.description; let updateVehicleType: UpdateVehicleTypeCommand = { id: vehicleTypeId, - type: "", - description: "", + type, + description, }; await VehicleTypeCommandHandler.update(updateVehicleType); diff --git a/src/controller/admin/unit/wearableController.ts b/src/controller/admin/unit/wearableController.ts index 7775c36..b28fb46 100644 --- a/src/controller/admin/unit/wearableController.ts +++ b/src/controller/admin/unit/wearableController.ts @@ -24,7 +24,7 @@ export async function getAllWearables(req: Request, res: Response): Promise let [wearables, total] = await WearableService.getAll({ offset, count, search, noLimit, ids }); res.json({ - wearables: wearables, + wearables: WearableFactory.mapToBase(wearables), total: total, offset: offset, count: count, @@ -44,6 +44,25 @@ export async function getWearableById(req: Request, res: Response): Promise res.json(WearableFactory.mapToSingle(wearable)); } +/** + * @description get wearable by Ids + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getWearablesByIds(req: Request, res: Response): Promise { + let ids = req.body.ids as Array; + + let [wearables, total] = await WearableService.getAll({ noLimit: true, ids }); + + res.json({ + wearables: WearableFactory.mapToBase(wearables), + total: total, + offset: 0, + count: total, + }); +} + /** * @description create wearable * @param req {Request} Express req object @@ -51,13 +70,20 @@ export async function getWearableById(req: Request, res: Response): Promise * @returns {Promise<*>} */ export async function createWearable(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const name = req.body.name; + const code = req.body.code || null; + const location = req.body.location; + const commissioned = req.body.commissioned; + const wearableTypeId = req.body.wearableTypeId; + const wearerId = req.body.wearerId || null; let createWearable: CreateWearableCommand = { - name: "", - location: "", - commissioned: undefined, - wearableTypeId: "", + code, + name, + location, + commissioned, + wearableTypeId, + wearerId, }; let wearableId = await WearableCommandHandler.create(createWearable); @@ -72,13 +98,21 @@ export async function createWearable(req: Request, res: Response): Promise */ export async function updateWearableById(req: Request, res: Response): Promise { const wearableId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const name = req.body.name; + const code = req.body.code || null; + const location = req.body.location; + const commissioned = req.body.commissioned; + const decommissioned = req.body.decommissioned || null; + const wearerId = req.body.wearerId || null; let updateWearable: UpdateWearableCommand = { id: wearableId, - name: "", - location: "", - commissioned: undefined, + code, + name, + location, + commissioned, + decommissioned, + wearerId, }; await WearableCommandHandler.update(updateWearable); diff --git a/src/controller/admin/unit/wearableTypeController.ts b/src/controller/admin/unit/wearableTypeController.ts index 40def8b..8597916 100644 --- a/src/controller/admin/unit/wearableTypeController.ts +++ b/src/controller/admin/unit/wearableTypeController.ts @@ -19,12 +19,11 @@ export async function getAllWearableTypes(req: Request, res: Response): Promise< let count = parseInt((req.query.count as string) ?? "25"); let search = (req.query.search as string) ?? ""; let noLimit = req.query.noLimit === "true"; - let ids = ((req.query.ids ?? "") as string).split(",").filter((i) => i); - let [wearableTypes, total] = await WearableTypeService.getAll({ offset, count, search, noLimit, ids }); + let [wearableTypes, total] = await WearableTypeService.getAll({ offset, count, search, noLimit }); res.json({ - wearableTypes: wearableTypes, + wearableTypes: WearableTypeFactory.mapToBase(wearableTypes), total: total, offset: offset, count: count, @@ -51,11 +50,12 @@ export async function getWearableTypeById(req: Request, res: Response): Promise< * @returns {Promise<*>} */ export async function createWearableType(req: Request, res: Response): Promise { - const salutationId = parseInt(req.body.salutationId); + const type = req.body.type; + const description = req.body.description; let createWearableType: CreateWearableTypeCommand = { - type: "", - description: "", + type, + description, }; let wearableTypeId = await WearableTypeCommandHandler.create(createWearableType); @@ -70,12 +70,13 @@ export async function createWearableType(req: Request, res: Response): Promise { const wearableTypeId = req.params.id; - const salutationId = parseInt(req.body.salutationId); + const type = req.body.type; + const description = req.body.description; let updateWearableType: UpdateWearableTypeCommand = { id: wearableTypeId, - type: "", - description: "", + type, + description, }; await WearableTypeCommandHandler.update(updateWearableType); diff --git a/src/entity/unit/equipment/equipment.ts b/src/entity/unit/equipment/equipment.ts index d55ea0d..bbd12a0 100644 --- a/src/entity/unit/equipment/equipment.ts +++ b/src/entity/unit/equipment/equipment.ts @@ -18,10 +18,10 @@ export class equipment { @Column({ type: "varchar", length: 255 }) location: string; - @Column({ type: getTypeByORM("datetime").type as ColumnType }) + @Column({ type: getTypeByORM("date").type as ColumnType }) commissioned: Date; - @Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null }) + @Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null }) decommissioned?: Date; @Column() diff --git a/src/entity/unit/equipment/equipmentType.ts b/src/entity/unit/equipment/equipmentType.ts index 3888ebe..3d0b134 100644 --- a/src/entity/unit/equipment/equipmentType.ts +++ b/src/entity/unit/equipment/equipmentType.ts @@ -16,6 +16,6 @@ export class equipmentType { @OneToMany(() => equipment, (e) => e.equipmentType, { cascade: ["insert"] }) equipment: equipment[]; - @OneToMany(() => inspectionPlan, (ip) => ip.equipment) + @OneToMany(() => inspectionPlan, (ip) => ip.equipmentType) inspectionPlans: inspectionPlan[]; } diff --git a/src/entity/unit/inspection/inspectionPlan.ts b/src/entity/unit/inspection/inspectionPlan.ts index f94bf5a..b2a43eb 100644 --- a/src/entity/unit/inspection/inspectionPlan.ts +++ b/src/entity/unit/inspection/inspectionPlan.ts @@ -1,8 +1,8 @@ import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm"; -import { equipment } from "../equipment/equipment"; -import { vehicle } from "../vehicle/vehicle"; import { PlanTimeDefinition } from "../../../viewmodel/admin/unit/inspection/inspectionPlan.models"; import { inspectionVersionedPlan } from "./inspectionVersionedPlan"; +import { equipmentType } from "../equipment/equipmentType"; +import { vehicleType } from "../vehicle/vehicleType"; @Entity() export class inspectionPlan { @@ -22,24 +22,24 @@ export class inspectionPlan { createdAt: Date; @Column() - equipmentId?: string; + equipmentTypeId?: string; @Column() - vehicleId?: string; + vehicleTypeId?: string; - @ManyToOne(() => equipment, { + @ManyToOne(() => equipmentType, { nullable: true, onDelete: "CASCADE", onUpdate: "RESTRICT", }) - equipment?: equipment; + equipmentType?: equipmentType; - @ManyToOne(() => vehicle, { + @ManyToOne(() => vehicleType, { nullable: true, onDelete: "CASCADE", onUpdate: "RESTRICT", }) - vehicle?: vehicle; + vehicleType?: vehicleType; @OneToMany(() => inspectionVersionedPlan, (ivp) => ivp.inspectionPlan, { cascade: ["insert"], diff --git a/src/entity/unit/vehicle/vehicle.ts b/src/entity/unit/vehicle/vehicle.ts index dc4a8d6..c09a28d 100644 --- a/src/entity/unit/vehicle/vehicle.ts +++ b/src/entity/unit/vehicle/vehicle.ts @@ -18,10 +18,10 @@ export class vehicle { @Column({ type: "varchar", length: 255 }) location: string; - @Column({ type: getTypeByORM("datetime").type as ColumnType }) + @Column({ type: getTypeByORM("date").type as ColumnType }) commissioned: Date; - @Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null }) + @Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null }) decommissioned?: Date; @Column() diff --git a/src/entity/unit/vehicle/vehicleType.ts b/src/entity/unit/vehicle/vehicleType.ts index d58b478..a3e3403 100644 --- a/src/entity/unit/vehicle/vehicleType.ts +++ b/src/entity/unit/vehicle/vehicleType.ts @@ -16,6 +16,6 @@ export class vehicleType { @OneToMany(() => vehicle, (e) => e.vehicleType, { cascade: ["insert"] }) vehicle: vehicle[]; - @OneToMany(() => inspectionPlan, (ip) => ip.vehicle) + @OneToMany(() => inspectionPlan, (ip) => ip.vehicleType) inspectionPlans: inspectionPlan[]; } diff --git a/src/entity/unit/wearable/wearable.ts b/src/entity/unit/wearable/wearable.ts index 3b1ea39..0313997 100644 --- a/src/entity/unit/wearable/wearable.ts +++ b/src/entity/unit/wearable/wearable.ts @@ -19,10 +19,10 @@ export class wearable { @Column({ type: "varchar", length: 255 }) location: string; - @Column({ type: getTypeByORM("datetime").type as ColumnType }) + @Column({ type: getTypeByORM("date").type as ColumnType }) commissioned: Date; - @Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null }) + @Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null }) decommissioned?: Date; @Column() diff --git a/src/factory/admin/club/member/member.ts b/src/factory/admin/club/member/member.ts index 246c0ae..4e953cb 100644 --- a/src/factory/admin/club/member/member.ts +++ b/src/factory/admin/club/member/member.ts @@ -15,7 +15,7 @@ export default abstract class MemberFactory { public static mapToSingle(record: member): MemberViewModel { return { id: record?.id, - salutation: SalutationFactory.mapToSingle(record?.salutation), + salutation: record?.salutation ? SalutationFactory.mapToSingle(record?.salutation) : null, firstname: record?.firstname, lastname: record?.lastname, nameaffix: record?.nameaffix, diff --git a/src/factory/admin/unit/inspection/inspectionPlan.ts b/src/factory/admin/unit/inspection/inspectionPlan.ts index 2e8fe5b..1a0439d 100644 --- a/src/factory/admin/unit/inspection/inspectionPlan.ts +++ b/src/factory/admin/unit/inspection/inspectionPlan.ts @@ -1,7 +1,9 @@ import { inspectionPlan } from "../../../../entity/unit/inspection/inspectionPlan"; import { 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 InspectionPointFactory from "./inspectionPoint"; export default abstract class InspectionPlanFactory { @@ -16,19 +18,21 @@ export default abstract class InspectionPlanFactory { title: record.title, inspectionInterval: record.inspectionInterval, remindTime: record.remindTime, - version: record.latestVersionedPlan.version, + version: record?.latestVersionedPlan?.version ?? 0, created: record.createdAt, - inspectionPoints: InspectionPointFactory.mapToBase(record.latestVersionedPlan.inspectionPoints), - ...(record.equipmentId + inspectionPoints: record.latestVersionedPlan + ? InspectionPointFactory.mapToBase(record.latestVersionedPlan.inspectionPoints) + : [], + ...(record.equipmentTypeId ? { - relatedId: record.equipmentId, + relatedId: record.equipmentTypeId, assigned: "equipment", - related: EquipmentFactory.mapToSingle(record.equipment), + related: EquipmentTypeFactory.mapToSingle(record.equipmentType), } : { - relatedId: record.vehicleId, + relatedId: record.vehicleTypeId, assigned: "vehicle", - related: VehicleFactory.mapToSingle(record.vehicle), + related: VehicleTypeFactory.mapToSingle(record.vehicleType), }), }; } diff --git a/src/helpers/typeTester.ts b/src/helpers/typeTester.ts new file mode 100644 index 0000000..ab37808 --- /dev/null +++ b/src/helpers/typeTester.ts @@ -0,0 +1,18 @@ +import { PlanTimeDefinition } from "../viewmodel/admin/unit/inspection/inspectionPlan.models"; + +export default abstract class TypeTester { + static testPlanTimeDefinition(val: string, key: string = "", throwErr: boolean = false): PlanTimeDefinition | null { + if (/^(\d+-(d|m|y)|\d+\/(\d+|\*))$/.test(val)) { + return val as PlanTimeDefinition; + } else if (throwErr) { + throw Error( + [ + key, + "provided String does not match PlanTimeDefinition Format: ${number}-${'d'|'m'|'y'} or ${number}/${number|'*'}", + ].join(": ") + ); + } else { + return null; + } + } +} diff --git a/src/migrations/baseSchemaTables/inspection.ts b/src/migrations/baseSchemaTables/inspection.ts index b064cb6..bfa480a 100644 --- a/src/migrations/baseSchemaTables/inspection.ts +++ b/src/migrations/baseSchemaTables/inspection.ts @@ -9,21 +9,21 @@ export const inspection_plan_table = new Table({ { name: "inspectionInterval", ...getTypeByORM("varchar") }, { name: "remindTime", ...getTypeByORM("varchar") }, { name: "createdAt", ...getTypeByORM("date"), default: getDefaultByORM("currentTimestamp") }, - { name: "equipmentId", ...getTypeByORM("uuid", true), default: getDefaultByORM("null") }, - { name: "vehicleId", ...getTypeByORM("uuid", true), default: getDefaultByORM("null") }, + { name: "equipmentTypeId", ...getTypeByORM("uuid", true), default: getDefaultByORM("null") }, + { name: "vehicleTypeId", ...getTypeByORM("uuid", true), default: getDefaultByORM("null") }, ], foreignKeys: [ new TableForeignKey({ - columnNames: ["equipmentId"], + columnNames: ["equipmentTypeId"], referencedColumnNames: ["id"], - referencedTableName: "equipment", + referencedTableName: "equipment_type", onDelete: "CASCADE", onUpdate: "RESTRICT", }), new TableForeignKey({ - columnNames: ["vehicleId"], + columnNames: ["vehicleTypeId"], referencedColumnNames: ["id"], - referencedTableName: "vehicle", + referencedTableName: "vehicle_type", onDelete: "CASCADE", onUpdate: "RESTRICT", }), diff --git a/src/routes/admin/index.ts b/src/routes/admin/index.ts index 13e48f5..782f89b 100644 --- a/src/routes/admin/index.ts +++ b/src/routes/admin/index.ts @@ -40,6 +40,7 @@ import wearable from "./unit/wearable"; import wearableType from "./unit/wearableType"; import inspection from "./unit/inspection"; import inspectionPlan from "./unit/inspectionPlan"; +import damageReport from "./unit/damageReport"; var router = express.Router({ mergeParams: true }); @@ -215,5 +216,15 @@ router.use( ]), inspectionPlan ); +router.use( + "/damagereport", + PermissionHelper.passCheckSomeMiddleware([ + { requiredPermission: "read", section: "unit", module: "damage_report" }, + { requiredPermission: "read", section: "unit", module: "equipment" }, + { requiredPermission: "read", section: "unit", module: "vehicle" }, + { requiredPermission: "read", section: "unit", module: "wearable" }, + ]), + damageReport +); export default router; diff --git a/src/routes/admin/unit/damageReport.ts b/src/routes/admin/unit/damageReport.ts new file mode 100644 index 0000000..aee6261 --- /dev/null +++ b/src/routes/admin/unit/damageReport.ts @@ -0,0 +1,50 @@ +import express, { Request, Response } from "express"; +import PermissionHelper from "../../../helpers/permissionHelper"; +import { + createInspection, + deleteInspectionById, + getAllInspectionsForRelated, + getInspectionById, + updateInspectionById, +} from "../../../controller/admin/unit/inspectionController"; +import { + getAllDamageReportsByStatus, + getAllDamageReportsForRelated, + getDamageReportById, + updateDamageReportById, +} from "../../../controller/admin/unit/damageReportController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllDamageReportsByStatus(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 getAllDamageReportsForRelated(req, res); + } +); + +router.get("/:id", async (req: Request, res: Response) => { + await getDamageReportById(req, res); +}); + +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "unit", "inspection"), + async (req: Request, res: Response) => { + await updateDamageReportById(req, res); + } +); + +export default router; diff --git a/src/routes/admin/unit/inspectionPlan.ts b/src/routes/admin/unit/inspectionPlan.ts index 0e33d5c..632c130 100644 --- a/src/routes/admin/unit/inspectionPlan.ts +++ b/src/routes/admin/unit/inspectionPlan.ts @@ -3,6 +3,7 @@ import PermissionHelper from "../../../helpers/permissionHelper"; import { createInspectionPlan, deleteInspectionPlanById, + getAllInspectionPlans, getAllInspectionPlansForRelated, getInspectionPlanById, updateInspectionPlanById, @@ -10,6 +11,10 @@ import { var router = express.Router({ mergeParams: true }); +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"; diff --git a/src/routes/admin/unit/vehicle.ts b/src/routes/admin/unit/vehicle.ts index 832e248..7ca588c 100644 --- a/src/routes/admin/unit/vehicle.ts +++ b/src/routes/admin/unit/vehicle.ts @@ -5,6 +5,7 @@ import { deleteVehicleById, getAllVehicles, getVehicleById, + getVehiclesByIds, updateVehicleById, } from "../../../controller/admin/unit/vehicleController"; @@ -18,6 +19,10 @@ router.get("/:id", async (req: Request, res: Response) => { await getVehicleById(req, res); }); +router.post("/ids", async (req: Request, res: Response) => { + await getVehiclesByIds(req, res); +}); + router.post( "/", PermissionHelper.passCheckMiddleware("create", "unit", "vehicle"), diff --git a/src/routes/admin/unit/wearable.ts b/src/routes/admin/unit/wearable.ts index c25226a..e1c1730 100644 --- a/src/routes/admin/unit/wearable.ts +++ b/src/routes/admin/unit/wearable.ts @@ -5,6 +5,7 @@ import { deleteWearableById, getAllWearables, getWearableById, + getWearablesByIds, updateWearableById, } from "../../../controller/admin/unit/wearableController"; @@ -18,6 +19,10 @@ router.get("/:id", async (req: Request, res: Response) => { await getWearableById(req, res); }); +router.post("/ids", async (req: Request, res: Response) => { + await getWearablesByIds(req, res); +}); + router.post( "/", PermissionHelper.passCheckMiddleware("create", "unit", "wearable"), diff --git a/src/routes/admin/unit/wearableType.ts b/src/routes/admin/unit/wearableType.ts index b61584f..983e401 100644 --- a/src/routes/admin/unit/wearableType.ts +++ b/src/routes/admin/unit/wearableType.ts @@ -2,11 +2,11 @@ import express, { Request, Response } from "express"; import PermissionHelper from "../../../helpers/permissionHelper"; import { createWearableType, + deleteWearableTypeById, getAllWearableTypes, getWearableTypeById, updateWearableTypeById, } from "../../../controller/admin/unit/wearableTypeController"; -import { deleteWearableById } from "../../../controller/admin/unit/wearableController"; var router = express.Router({ mergeParams: true }); @@ -38,7 +38,7 @@ router.delete( "/:id", PermissionHelper.passCheckMiddleware("delete", "unit", "wearable_type"), async (req: Request, res: Response) => { - await deleteWearableById(req, res); + await deleteWearableTypeById(req, res); } ); diff --git a/src/service/unit/damageReportService.ts b/src/service/unit/damageReportService.ts index 7821ea1..622b377 100644 --- a/src/service/unit/damageReportService.ts +++ b/src/service/unit/damageReportService.ts @@ -3,20 +3,73 @@ import { damageReport } from "../../entity/unit/damageReport"; import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class DamageReportService { - /** - * @description get all damageReports - * @returns {Promise>} - */ - static async getAll(): Promise> { - return await dataSource + private static query = () => + dataSource .getRepository(damageReport) .createQueryBuilder("damageReport") .leftJoinAndSelect("damageReport.equipment", "equipment") .leftJoinAndSelect("damageReport.vehicle", "vehicle") .leftJoinAndSelect("damageReport.wearable", "wearable") - .leftJoinAndSelect("damageReport.maintenance", "maintenance") - .orderBy("type", "ASC") - .getMany() + .leftJoinAndSelect("damageReport.maintenance", "maintenance"); + + /** + * @description get all damageReports By done + * @returns {Promise<[Array, number]>} + */ + static async getAll( + done = false, + { + offset = 0, + count = 25, + noLimit = false, + }: { + offset?: number; + count?: number; + noLimit?: boolean; + } + ): Promise<[Array, number]> { + let query = this.query().where({ done }); + + if (!noLimit) { + query = query.offset(offset).limit(count); + } + + return await query + .orderBy("damageReport.reportedAt", "ASC") + .getManyAndCount() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "damageReport", err); + }); + } + + /** + * @description get all damageReports By related + * @returns {Promise<[Array, 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, number]> { + let query = this.query().where(where); + + if (!noLimit) { + query = query.offset(offset).limit(count); + } + + return await query + .orderBy("reportedAt", "ASC") + .getManyAndCount() .then((res) => { return res; }) @@ -30,13 +83,7 @@ export default abstract class DamageReportService { * @returns {Promise} */ static async getById(id: string): Promise { - return await dataSource - .getRepository(damageReport) - .createQueryBuilder("damageReport") - .leftJoinAndSelect("damageReport.equipment", "equipment") - .leftJoinAndSelect("damageReport.vehicle", "vehicle") - .leftJoinAndSelect("damageReport.wearable", "wearable") - .leftJoinAndSelect("damageReport.maintenance", "maintenance") + return await this.query() .where({ id }) .getOneOrFail() .then((res) => { diff --git a/src/service/unit/equipment/equipmentService.ts b/src/service/unit/equipment/equipmentService.ts index 7e2267b..921f574 100644 --- a/src/service/unit/equipment/equipmentService.ts +++ b/src/service/unit/equipment/equipmentService.ts @@ -27,11 +27,16 @@ export default abstract class EquipmentService { .leftJoinAndSelect("equipment.equipmentType", "equipmenttype"); if (search != "") { - query = query.where({ - code: Like(search), - name: Like(search), - location: Like(search), - }); + query = query + .where({ + code: Like(`%${search}%`), + }) + .orWhere({ + name: Like(`%${search}%`), + }) + .orWhere({ + location: Like(`%${search}%`), + }); } if (ids.length != 0) { diff --git a/src/service/unit/equipment/equipmentTypeService.ts b/src/service/unit/equipment/equipmentTypeService.ts index 8789fe7..b85b9f1 100644 --- a/src/service/unit/equipment/equipmentTypeService.ts +++ b/src/service/unit/equipment/equipmentTypeService.ts @@ -13,26 +13,20 @@ export default abstract class EquipmentTypeService { count = 25, search = "", noLimit = false, - ids = [], }: { offset?: number; count?: number; search?: string; noLimit?: boolean; - ids?: Array; }): Promise<[Array, number]> { let query = dataSource.getRepository(equipmentType).createQueryBuilder("equipmentType"); if (search != "") { query = query.where({ - type: Like(search), + type: Like(`%${search}%`), }); } - if (ids.length != 0) { - query = query.where({ id: In(ids) }); - } - if (!noLimit) { query = query.offset(offset).limit(count); } diff --git a/src/service/unit/inspection/inspectionPlanService.ts b/src/service/unit/inspection/inspectionPlanService.ts index 2514ad1..197912d 100644 --- a/src/service/unit/inspection/inspectionPlanService.ts +++ b/src/service/unit/inspection/inspectionPlanService.ts @@ -14,19 +14,63 @@ export default abstract class InspectionPlanService { "inspectionPlan.versionedPlans", "latestVersionedPlan", DB_TYPE == "postgres" - ? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."start") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")' - : "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.start) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)" + ? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."createdAt") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")' + : "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.createdAt) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)" ) .leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints") - .leftJoinAndSelect("inspectionPlan.equipment", "equipment") - .leftJoinAndSelect("inspectionPlan.vehicle", "vehicle"); + .leftJoinAndSelect("inspectionPlan.equipmentType", "equipmentType") + .leftJoinAndSelect("inspectionPlan.vehicleType", "vehicleType"); + + /** + * @description get all inspectionPlans for related + * @returns {Promise<[Array, number]>} + */ + static async getAll({ + offset = 0, + count = 25, + search = "", + noLimit = false, + ids = [], + }: { + offset?: number; + count?: number; + search?: string; + noLimit?: boolean; + ids?: Array; + }): Promise<[Array, number]> { + let query = this.query(); + + if (search != "") { + query = query.where({ + title: Like(`%${search}%`), + }); + } + + if (ids.length != 0) { + query = query.where({ id: In(ids) }); + } + + if (!noLimit) { + query = query.offset(offset).limit(count); + } + + return await query + .orderBy("inspectionPlan.title", "ASC") + .getManyAndCount() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPlan", err); + }); + } /** * @description get all inspectionPlans for related * @returns {Promise<[Array, number]>} */ static async getAllForRelated( - where: { equipmentId: string } | { vehicleId: string }, + where: { equipmentTypeId: string } | { vehicleTypeId: string }, { offset = 0, count = 25, @@ -44,13 +88,13 @@ export default abstract class InspectionPlanService { let query = this.query().where(where); if (search != "") { - query = query.where({ - title: Like(search), + query = query.andWhere({ + title: Like(`%${search}%`), }); } if (ids.length != 0) { - query = query.where({ id: In(ids) }); + query = query.andWhere({ id: In(ids) }); } if (!noLimit) { @@ -58,7 +102,7 @@ export default abstract class InspectionPlanService { } return await query - .orderBy("title", "ASC") + .orderBy("inspectionPlan.title", "ASC") .getManyAndCount() .then((res) => { return res; diff --git a/src/service/unit/inspection/inspectionService.ts b/src/service/unit/inspection/inspectionService.ts index 709b335..08ec621 100644 --- a/src/service/unit/inspection/inspectionService.ts +++ b/src/service/unit/inspection/inspectionService.ts @@ -38,7 +38,7 @@ export default abstract class InspectionService { } return await query - .orderBy("createdAt", "DESC") + .orderBy("inspection.createdAt", "DESC") .getManyAndCount() .then((res) => { return res; diff --git a/src/service/unit/vehicle/vehicleService.ts b/src/service/unit/vehicle/vehicleService.ts index 921a981..61c2b73 100644 --- a/src/service/unit/vehicle/vehicleService.ts +++ b/src/service/unit/vehicle/vehicleService.ts @@ -27,11 +27,16 @@ export default abstract class VehicleService { .leftJoinAndSelect("vehicle.vehicleType", "vehicletype"); if (search != "") { - query = query.where({ - code: Like(search), - name: Like(search), - location: Like(search), - }); + query = query + .where({ + code: Like(`%${search}%`), + }) + .orWhere({ + name: Like(`%${search}%`), + }) + .orWhere({ + location: Like(`%${search}%`), + }); } if (ids.length != 0) { diff --git a/src/service/unit/vehicle/vehicleTypeService.ts b/src/service/unit/vehicle/vehicleTypeService.ts index 6ecb703..c1dbdf2 100644 --- a/src/service/unit/vehicle/vehicleTypeService.ts +++ b/src/service/unit/vehicle/vehicleTypeService.ts @@ -13,26 +13,20 @@ export default abstract class VehicleTypeService { count = 25, search = "", noLimit = false, - ids = [], }: { offset?: number; count?: number; search?: string; noLimit?: boolean; - ids?: Array; }): Promise<[Array, number]> { let query = dataSource.getRepository(vehicleType).createQueryBuilder("vehicleType"); if (search != "") { query = query.where({ - type: Like(search), + type: Like(`%${search}%`), }); } - if (ids.length != 0) { - query = query.where({ id: In(ids) }); - } - if (!noLimit) { query = query.offset(offset).limit(count); } diff --git a/src/service/unit/wearable/wearableService.ts b/src/service/unit/wearable/wearableService.ts index b369f47..d016b0f 100644 --- a/src/service/unit/wearable/wearableService.ts +++ b/src/service/unit/wearable/wearableService.ts @@ -28,11 +28,16 @@ export default abstract class WearableService { .leftJoinAndSelect("wearable.wearer", "wearer"); if (search != "") { - query = query.where({ - code: Like(search), - name: Like(search), - location: Like(search), - }); + query = query + .where({ + code: Like(`%${search}%`), + }) + .orWhere({ + name: Like(`%${search}%`), + }) + .orWhere({ + location: Like(`%${search}%`), + }); } if (ids.length != 0) { @@ -63,6 +68,7 @@ export default abstract class WearableService { .getRepository(wearable) .createQueryBuilder("wearable") .leftJoinAndSelect("wearable.wearableType", "wearabletype") + .leftJoinAndSelect("wearable.wearer", "wearer") .where({ id }) .getOneOrFail() .then((res) => { diff --git a/src/service/unit/wearable/wearableTypeService.ts b/src/service/unit/wearable/wearableTypeService.ts index d6f167f..cd91a26 100644 --- a/src/service/unit/wearable/wearableTypeService.ts +++ b/src/service/unit/wearable/wearableTypeService.ts @@ -13,26 +13,20 @@ export default abstract class WearableTypeService { count = 25, search = "", noLimit = false, - ids = [], }: { offset?: number; count?: number; search?: string; noLimit?: boolean; - ids?: Array; }): Promise<[Array, number]> { let query = dataSource.getRepository(wearableType).createQueryBuilder("wearableType"); if (search != "") { query = query.where({ - type: Like(search), + type: Like(`%${search}%`), }); } - if (ids.length != 0) { - query = query.where({ id: In(ids) }); - } - if (!noLimit) { query = query.offset(offset).limit(count); } diff --git a/src/viewmodel/admin/unit/inspection/inspectionPlan.models.ts b/src/viewmodel/admin/unit/inspection/inspectionPlan.models.ts index cbbea41..fe215d5 100644 --- a/src/viewmodel/admin/unit/inspection/inspectionPlan.models.ts +++ b/src/viewmodel/admin/unit/inspection/inspectionPlan.models.ts @@ -1,6 +1,8 @@ import { InspectionPointEnum } from "../../../../enums/inspectionEnum"; 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"; export type PlanTimeDefinition = `${number}-${"d" | "m" | "y"}` | `${number}/${number | "*"}`; @@ -16,11 +18,11 @@ export type InspectionPlanViewModel = { } & ( | { assigned: "equipment"; - related: EquipmentViewModel; + related: EquipmentTypeViewModel; } | { assigned: "vehicle"; - related: VehicleViewModel; + related: VehicleTypeViewModel; } );