2025-05-31 15:12:16 +02:00
|
|
|
import { Request, Response } from "express";
|
|
|
|
import WearableService from "../../../service/unit/wearable/wearableService";
|
|
|
|
import WearableFactory from "../../../factory/admin/unit/wearable/wearable";
|
|
|
|
import {
|
|
|
|
CreateWearableCommand,
|
|
|
|
DeleteWearableCommand,
|
|
|
|
UpdateWearableCommand,
|
|
|
|
} from "../../../command/unit/wearable/wearableCommand";
|
|
|
|
import WearableCommandHandler from "../../../command/unit/wearable/wearableCommandHandler";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get all wearables
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function getAllWearables(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);
|
|
|
|
|
|
|
|
//{ offset, count, search, noLimit, ids }
|
|
|
|
let [wearables, total] = await WearableService.getAll();
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
wearables: wearables,
|
|
|
|
total: total,
|
|
|
|
offset: offset,
|
|
|
|
count: count,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get wearable by id
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function getWearableById(req: Request, res: Response): Promise<any> {
|
|
|
|
const wearableId = req.params.id;
|
|
|
|
let wearable = await WearableService.getById(wearableId);
|
|
|
|
|
|
|
|
res.json(WearableFactory.mapToSingle(wearable));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description create wearable
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function createWearable(req: Request, res: Response): Promise<any> {
|
|
|
|
const salutationId = parseInt(req.body.salutationId);
|
|
|
|
|
|
|
|
let createWearable: CreateWearableCommand = {
|
|
|
|
name: "",
|
|
|
|
location: "",
|
|
|
|
commissioned: undefined,
|
|
|
|
wearableTypeId: "",
|
|
|
|
};
|
|
|
|
let wearableId = await WearableCommandHandler.create(createWearable);
|
|
|
|
|
|
|
|
res.status(200).send(wearableId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description update wearable by id
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function updateWearableById(req: Request, res: Response): Promise<any> {
|
|
|
|
const wearableId = req.params.id;
|
|
|
|
const salutationId = parseInt(req.body.salutationId);
|
|
|
|
|
|
|
|
let updateWearable: UpdateWearableCommand = {
|
|
|
|
id: wearableId,
|
|
|
|
name: "",
|
|
|
|
location: "",
|
|
|
|
commissioned: undefined,
|
|
|
|
};
|
|
|
|
await WearableCommandHandler.update(updateWearable);
|
|
|
|
|
|
|
|
res.sendStatus(204);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description delete wearable by id
|
|
|
|
* @param req {Request} Express req object
|
|
|
|
* @param res {Response} Express res object
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
|
|
|
export async function deleteWearableById(req: Request, res: Response): Promise<any> {
|
|
|
|
const wearableId = req.params.id;
|
|
|
|
|
|
|
|
let deleteWearable: DeleteWearableCommand = {
|
|
|
|
id: wearableId,
|
|
|
|
};
|
|
|
|
await WearableCommandHandler.delete(deleteWearable);
|
|
|
|
|
|
|
|
res.sendStatus(204);
|
|
|
|
}
|