From 0abd531b7982af25f32be11d3d959bbe2919e010 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 3 May 2024 15:37:43 +0200 Subject: [PATCH] feat: Process generic updates (#148) --- .../api/genericUpdateController.ts | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/controllers/api/genericUpdateController.ts b/src/controllers/api/genericUpdateController.ts index f77e366f..ab8b8446 100644 --- a/src/controllers/api/genericUpdateController.ts +++ b/src/controllers/api/genericUpdateController.ts @@ -1,28 +1,12 @@ import { updateGeneric } from "@/src/services/inventoryService"; -import { IGenericUpdate } from "@/src/types/genericUpdate"; import { RequestHandler } from "express"; +import { getJSONfromString } from "@/src/helpers/stringHelpers"; -// TODO: Nightwave evidence submission support is the only thing missing. -// TODO: this was added by someone without testing. It may not work. // eslint-disable-next-line @typescript-eslint/no-misused-promises -const genericUpdateController: RequestHandler = async (_request, response) => { - // const accountId = request.query.accountId as string; - - // const [body] = String(request.body).split("\n"); - - // let reply = {}; - // try { - // const update = JSON.parse(body) as IGenericUpdate; - // if (typeof update !== "object") { - // throw new Error("Invalid data format"); - // } - - // reply = await updateGeneric(update, accountId); - // } catch (err) { - // console.error("Error parsing JSON data:", err); - // } - - response.json({}); +const genericUpdateController: RequestHandler = async (request, response) => { + const accountId = request.query.accountId as string; + const update = getJSONfromString(request.body.toString()); + response.json(await updateGeneric(update, accountId)); }; export { genericUpdateController };