change according to connection from frontend
This commit is contained in:
parent
2609ecc1bf
commit
e3db523a0e
36 changed files with 611 additions and 173 deletions
113
src/controller/admin/unit/damageReportController.ts
Normal file
113
src/controller/admin/unit/damageReportController.ts
Normal file
|
@ -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<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 [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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
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);
|
||||
}
|
|
@ -24,7 +24,7 @@ export async function getAllEquipments(req: Request, res: Response): Promise<any
|
|||
let [equipments, total] = await EquipmentService.getAll({ offset, count, search, noLimit, ids });
|
||||
|
||||
res.json({
|
||||
equipments: equipments,
|
||||
equipments: EquipmentFactory.mapToBase(equipments),
|
||||
total: total,
|
||||
offset: offset,
|
||||
count: count,
|
||||
|
@ -70,13 +70,18 @@ export async function getEquipmentsByIds(req: Request, res: Response): Promise<a
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createEquipment(req: Request, res: Response): Promise<any> {
|
||||
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<any>
|
|||
*/
|
||||
export async function updateEquipmentById(req: Request, res: Response): Promise<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<any> {
|
||||
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<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<an
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createInspection(req: Request, res: Response): Promise<any> {
|
||||
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<any
|
|||
*/
|
||||
export async function updateInspectionById(req: Request, res: Response): Promise<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ export async function getAllVehicles(req: Request, res: Response): Promise<any>
|
|||
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<any>
|
|||
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<any> {
|
||||
let ids = req.body.ids as Array<string>;
|
||||
|
||||
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<any>
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createVehicle(req: Request, res: Response): Promise<any> {
|
||||
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<any> {
|
|||
*/
|
||||
export async function updateVehicleById(req: Request, res: Response): Promise<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -19,12 +19,11 @@ export async function getAllVehicleTypes(req: Request, res: Response): Promise<a
|
|||
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 [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<a
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createVehicleType(req: Request, res: Response): Promise<any> {
|
||||
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<an
|
|||
*/
|
||||
export async function updateVehicleTypeById(req: Request, res: Response): Promise<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ export async function getAllWearables(req: Request, res: Response): Promise<any>
|
|||
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<any>
|
|||
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<any> {
|
||||
let ids = req.body.ids as Array<string>;
|
||||
|
||||
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<any>
|
|||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createWearable(req: Request, res: Response): Promise<any> {
|
||||
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<any>
|
|||
*/
|
||||
export async function updateWearableById(req: Request, res: Response): Promise<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<any> {
|
||||
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<a
|
|||
*/
|
||||
export async function updateWearableTypeById(req: Request, res: Response): Promise<any> {
|
||||
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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue