2024-05-28 13:45:06 +02:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2024-04-04 01:55:51 +03:00
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { updateTheme } from "@/src/services/inventoryService";
|
|
|
|
import { IThemeUpdateRequest } from "@/src/types/requestTypes";
|
|
|
|
import { RequestHandler } from "express";
|
|
|
|
|
|
|
|
const updateThemeController: RequestHandler = async (request, response) => {
|
2024-05-28 13:45:06 +02:00
|
|
|
const accountId = await getAccountIdForRequest(request);
|
2024-04-04 01:55:51 +03:00
|
|
|
const body = String(request.body);
|
|
|
|
|
|
|
|
try {
|
2025-01-24 14:27:10 +01:00
|
|
|
const json = getJSONfromString<IThemeUpdateRequest>(body);
|
2024-04-04 01:55:51 +03:00
|
|
|
if (typeof json !== "object") {
|
|
|
|
throw new Error("Invalid data format");
|
|
|
|
}
|
|
|
|
|
|
|
|
await updateTheme(json, accountId);
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error parsing JSON data:", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
response.json({});
|
|
|
|
};
|
|
|
|
|
|
|
|
export { updateThemeController };
|