253 lines
5.9 KiB
TypeScript
253 lines
5.9 KiB
TypeScript
import { Response } from "express";
|
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
|
import {
|
|
Add3DWidget,
|
|
Delete3Dwidget,
|
|
Get3Dwidget,
|
|
Update3Dwidget,
|
|
} from "../../../../shared/services/visualization/widget3dService.ts";
|
|
|
|
export const Add3dWidgetController = 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 Add3DWidget({
|
|
organization,
|
|
widget,
|
|
userId,
|
|
zoneId,
|
|
projectId,
|
|
});
|
|
|
|
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(200).json({
|
|
message: "Zone not found",
|
|
});
|
|
break;
|
|
case "Widget not updated":
|
|
res.status(200).json({
|
|
message: "Widget not updated",
|
|
});
|
|
break;
|
|
case "widget update successfully":
|
|
res.status(200).json({
|
|
message: "widget update successfully",
|
|
});
|
|
break;
|
|
case "Widget 3d not created":
|
|
res.status(200).json({
|
|
message: "Widget 3d not created",
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "Widget created successfully",
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
return;
|
|
}
|
|
};
|
|
export const Update3DwidgetController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { userId, organization } = req.user || {};
|
|
const { id, position, rotation, projectId, zoneId } = req.body;
|
|
if (
|
|
!userId ||
|
|
!organization ||
|
|
!id ||
|
|
!position ||
|
|
!rotation ||
|
|
!projectId ||
|
|
!zoneId
|
|
) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await Update3Dwidget({
|
|
organization,
|
|
id,
|
|
position,
|
|
rotation,
|
|
userId,
|
|
zoneId,
|
|
projectId,
|
|
});
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({
|
|
message: "User not found",
|
|
});
|
|
break;
|
|
case "Zone not found":
|
|
res.status(404).json({
|
|
message: "Zone not found",
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "widget3D update successfully",
|
|
});
|
|
break;
|
|
case "Widget not updated":
|
|
res.status(200).json({
|
|
message: "Widget not updated",
|
|
});
|
|
break;
|
|
case "widget not found":
|
|
res.status(200).json({
|
|
message: "widget not found",
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
return;
|
|
}
|
|
};
|
|
export const Delete3DwidgetController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { userId, organization } = req.user || {};
|
|
const { id, projectId, zoneId } = req.body;
|
|
if (!userId || !organization || !id || !projectId || !zoneId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await Delete3Dwidget({
|
|
organization,
|
|
id,
|
|
userId,
|
|
zoneId,
|
|
projectId,
|
|
});
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({
|
|
message: "User not found",
|
|
});
|
|
break;
|
|
case "Zone not found":
|
|
res.status(404).json({
|
|
message: "Zone not found",
|
|
});
|
|
break;
|
|
case "3D widget not found for the ID":
|
|
res.status(404).json({
|
|
message: "3D widget not found for the ID",
|
|
});
|
|
break;
|
|
case "3DWidget delete unsuccessfull":
|
|
res.status(200).json({
|
|
message: "3DWidget delete unsuccessfull",
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "3DWidget deleted successfully",
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
return;
|
|
}
|
|
};
|
|
export const Get3DWidgetController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { userId, organization } = req.user || {};
|
|
const { projectId, zoneId } = req.params;
|
|
if (!userId || !organization || !projectId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await Get3Dwidget({
|
|
organization,
|
|
userId,
|
|
zoneId,
|
|
projectId,
|
|
});
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({
|
|
message: "User not found",
|
|
});
|
|
break;
|
|
case "Zone not found":
|
|
res.status(404).json({
|
|
message: "Zone not found",
|
|
});
|
|
break;
|
|
case "All 3Dwidgets":
|
|
res.status(200).json([]);
|
|
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;
|
|
}
|
|
};
|