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

@@ -1,5 +1,5 @@
import * as express from "express";
import { FloatWidgetService } from "../controller/visualization/FloatWidgetService.ts";
import { FloatWidgetService } from "../controller/visualization/floatWidgetService.ts";
const router = express.Router();
router.post("/floatwidget/save", FloatWidgetService.addfloatWidget);
router.patch("/floatwidget/delete", FloatWidgetService.deletefloatWidget);

View File

@@ -0,0 +1,306 @@
import { Response } from "express";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
import {
AddFloat,
DelFloat,
DuplicateFloat,
GetFloatWidget,
SingleFloatWidget,
} from "../../../../shared/services/visualization/floatWidgetService.ts";
export const FloatAddController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { widget, zoneId, index, projectId } = req.body;
if (
!userId ||
!organization ||
!widget ||
!zoneId ||
!index ||
!projectId
) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await AddFloat({
organization,
widget,
zoneId,
index,
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 updated successfully":
res.status(200).json({
message: "Widget updated successfully",
});
break;
case "Failed to create FloatWidget":
res.status(400).json({
message: "Failed to create FloatWidget",
});
break;
case "Success":
res.status(200).json({
message: "FloatWidget 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 DeleteFloatController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { floatWidgetID, projectId, zoneId } = req.body;
if (!userId || !organization || !floatWidgetID || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await DelFloat({
organization,
floatWidgetID,
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 "FloatWidget not found for the Id":
res.status(404).json({
message: "FloatWidget not found for the Id",
});
break;
case "FloatWidget not deleted":
res.status(200).json({
message: "FloatWidget not deleted",
});
break;
case "Success":
res.status(200).json({
message: "FloatingWidget 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 DuplicateFloatController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { widget, projectId, zoneId, index } = req.body;
if (
!userId ||
!organization ||
!widget ||
!projectId ||
!zoneId ||
!index
) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await DuplicateFloat({
organization,
widget,
zoneId,
index,
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 "FloatWidget update unsuccessfull":
res.status(200).json({
message: "FloatWidget update unsuccessfull",
});
break;
case "Widget updated successfully":
res.status(200).json({
message: "Widget updated successfully",
});
break;
case "Failed to duplicate FloatWidget":
res.status(200).json({
message: "Failed to duplicate FloatWidget",
});
break;
case "Success":
res.status(200).json({
message: "Duplicate FloatWidget 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 GetFloatController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, zoneId } = req.params;
if (!userId || !organization || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await GetFloatWidget({
organization,
zoneId,
projectId,
userId,
});
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 Datas":
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;
}
};
export const SingleFloatController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { floatWidgetID } = req.params;
if (!userId || !organization || !floatWidgetID) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await SingleFloatWidget({
organization,
floatWidgetID,
userId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Widget not found":
res.status(404).json({
message: "Widget not found",
});
break;
case "Success":
res.status(200).json({
Data: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};

View File

@@ -0,0 +1,232 @@
import { Response } from "express";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
import {
AddPanel,
ClearPanel,
DelPanel,
LockedPanel,
} from "../../../../shared/services/visualization/panelService.ts";
export const AddPanelController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { panelOrder, zoneId, projectId } = req.body;
if (!userId || !organization || !panelOrder || !zoneId || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await AddPanel({
organization,
panelOrder,
zoneId,
projectId,
userId,
});
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 "No new panels were created. All panels already exist":
res.status(200).json({
message: "No new panels were created. All panels already exist",
});
break;
case "Success":
res.status(200).json({
message: "Panels created successfully",
panelID: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const DeletePanelController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { panelName, projectId, zoneId } = req.body;
if (!userId || !organization || !panelName || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await DelPanel({
organization,
panelName,
zoneId,
projectId,
userId,
});
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 "Panel Already Deleted":
res.status(409).json({
message: "Panel Already Deleted",
});
break;
case "Success":
res.status(200).json({
message: "Panel 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 ClearPanelController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { panelName, projectId, zoneId } = req.body;
if (!userId || !organization || !panelName || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await ClearPanel({
organization,
panelName,
zoneId,
projectId,
userId,
});
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 "Requested Panel not found":
res.status(200).json({
message: "Requested Panel not found",
});
break;
case "No widgets to clear":
res.status(200).json({
message: "No widgets to clear",
});
break;
case "Success":
res.status(200).json({
message: "PanelWidgets cleared successfully",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const LockedPanelController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, zoneId, lockedPanel } = req.body;
if (!userId || !organization || !projectId || !zoneId || !lockedPanel) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await LockedPanel({
organization,
zoneId,
lockedPanel,
userId,
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 "locked panel not updated":
res.status(200).json({
message: "locked panel not updated",
});
break;
case "Success":
res.status(200).json({
message: "locked panel updated successfully",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};

View File

@@ -0,0 +1,215 @@
import { Response } from "express";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
import {
AddTemplate,
AddTemplateToZone,
GetAllTemplates,
TemplateDelete,
} from "../../../../shared/services/visualization/templateService.ts";
export const AddTemplateController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { template, projectId } = req.body;
if (!userId || !organization || !template || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await AddTemplate({
organization,
template,
projectId,
userId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "TemplateID alreay exists":
res.status(200).json({
message: "TemplateID alreay exists",
});
break;
case "Template not saved":
res.status(200).json({
message: "Template not saved",
});
break;
case "Success":
res.status(200).json({
message: "Template saved successfully",
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const AddTemToZoneController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { templateID, projectId, zoneId } = req.body;
if (!userId || !organization || !templateID || !projectId || !zoneId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await AddTemplateToZone({
organization,
templateID,
zoneId,
projectId,
userId,
});
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 "TemplateID not found":
res.status(409).json({
message: "TemplateID not found",
});
break;
case "Success":
res.status(201).json({
message: "Template placed in Zone",
data: result.data,
});
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
return;
}
};
export const TemplateDeleteController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { templateID, projectId } = req.body;
if (!userId || !organization || !templateID || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await TemplateDelete({
userId,
organization,
templateID,
projectId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Template not found":
res.status(404).json({
message: "Template not found",
});
break;
case "Template not Deleted":
res.status(200).json({
message: "Template not Deleted",
});
break;
case "Success":
res.status(200).json({
message: "Template 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 GetTemplateController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId } = req.params;
if (!userId || !organization || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await GetAllTemplates({
organization,
userId,
projectId,
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "All Datas":
res.status(404).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;
}
};

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;
}
};

View File

@@ -0,0 +1,252 @@
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;
}
};

View File

@@ -129,7 +129,8 @@ export class Widget3dService {
widgetID: id,
isArchive: false,
});
if (!widgetData) return res.status(204).json({ message: "Widget not found" });
if (!widgetData)
return res.status(204).json({ message: "Widget not found" });
const structureData = {
measurements: widgetData?.Data?.measurements,
duration: widgetData?.Data?.duration,

View File

@@ -92,7 +92,7 @@ export class PanelService {
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
existingZone.panelOrder.indexOf(existingPanel.panelName);
const zonepanelname = await zoneSchema(organization).updateOne(
await zoneSchema(organization).updateOne(
{ _id: existingZone._id },
{ $pull: { panelOrder: existingPanel.panelName } }
);

View File

@@ -61,7 +61,6 @@ export class WidgetService {
return res
.status(200)
.json({ message: "Widget updated successfully" });
}
const newWidget = await widgetSchema(organization).create({
widgetID: widget.id,