change according to connection from frontend
This commit is contained in:
parent
2609ecc1bf
commit
e3db523a0e
36 changed files with 611 additions and 173 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue