Controller and routing for the Vizualtion and builder

This commit is contained in:
2025-05-29 15:34:12 +05:30
parent bea6044b25
commit c38a698692
34 changed files with 2523 additions and 926 deletions

View File

@@ -2,6 +2,8 @@ import { Response } from "express";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
import {
AddWidget,
GetWidget,
UpdateWidget,
WidgetDelete,
} from "../../../../shared/services/visualization/widgetService.ts";
@@ -128,3 +130,131 @@ export const WidgetDeleteController = async (
return;
}
};
export const WidgetUpdateController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { values, projectId, zoneId, widgetID } = req.body;
if (
!userId ||
!organization ||
!widgetID ||
!values ||
!projectId ||
!zoneId
) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await UpdateWidget({
organization,
values,
zoneId,
widgetID,
projectId,
userId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
});
break;
case "Data not found":
res.status(409).json({
message: "Data not found",
});
break;
case "Success":
res.status(200).json({
message: "Widget updated successfully",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const GetWidgetController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, zoneId, widgetID } = req.query as {
projectId: string;
zoneId: string;
widgetID: string;
};
if (!userId || !organization || !widgetID || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await GetWidget({
organization,
zoneId,
widgetID,
projectId,
userId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project 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 for the widgetID":
res.status(409).json({
message: "Widget not found for the widgetID",
});
break;
case "Success":
res.status(200).json(result.data);
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};