Controller service completed for Vizualization

This commit is contained in:
2025-05-28 18:29:17 +05:30
parent 6b5bee879b
commit 7fb2a6bd2d
18 changed files with 2895 additions and 16 deletions

View File

@@ -0,0 +1,130 @@
import { Response } from "express";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
import {
AddWidget,
WidgetDelete,
} from "../../../../shared/services/visualization/widgetService.ts";
export const AddWidgetController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { widget, projectId, zoneId } = req.body;
if (!userId || !organization || !widget || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await AddWidget({
organization,
widget,
projectId,
userId,
zoneId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found",
});
case "panelName not found":
res.status(404).json({
message: "panelName not found",
});
break;
case "Widget update unsuccessfull":
res.status(200).json({
message: "Widget update unsuccessfull",
});
break;
case "Widget update successfully":
res.status(200).json({
message: "Widget updated successfully",
});
break;
case "Success":
res.status(200).json({
message: "Widget created successfully",
});
break;
case "Type mismatch":
res.status(200).json({
message: "Type mismatch",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const WidgetDeleteController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { widgetID, projectId, zoneId } = req.body;
if (!userId || !organization || !widgetID || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await WidgetDelete({
organization,
widgetID,
zoneId,
projectId,
userId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
});
break;
case "Widget not found":
res.status(409).json({
message: "Widget not found",
});
break;
case "Success":
res.status(200).json({
message: "Widget deleted successfully",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};