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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue