Merge branch 'branch-v2' into branch-1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import { FloatWidgetService } from "../controller/visualization/FloatWidgetService.ts";
|
import { FloatWidgetService } from "../controller/visualization/floatWidgetService.ts";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.post("/floatwidget/save", FloatWidgetService.addfloatWidget);
|
router.post("/floatwidget/save", FloatWidgetService.addfloatWidget);
|
||||||
router.patch("/floatwidget/delete", FloatWidgetService.deletefloatWidget);
|
router.patch("/floatwidget/delete", FloatWidgetService.deletefloatWidget);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import { PanelService } from "../controller/visualization/PanelService.ts";
|
import { PanelService } from "../controller/visualization/panelService.ts";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
getEnvironment,
|
||||||
|
setEnvironment,
|
||||||
|
} from "../../../../shared/services/builder/EnvironmentService.ts";
|
||||||
|
|
||||||
|
export const SetEnvironmentController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
roofVisibility,
|
||||||
|
renderDistance,
|
||||||
|
limitDistance,
|
||||||
|
wallVisibility,
|
||||||
|
shadowVisibility,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!roofVisibility ||
|
||||||
|
!wallVisibility ||
|
||||||
|
!renderDistance ||
|
||||||
|
!limitDistance ||
|
||||||
|
!shadowVisibility ||
|
||||||
|
!projectId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
roofVisibility,
|
||||||
|
wallVisibility,
|
||||||
|
shadowVisibility,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
renderDistance,
|
||||||
|
limitDistance,
|
||||||
|
};
|
||||||
|
const result = await setEnvironment(data);
|
||||||
|
|
||||||
|
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 "environments updated":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetEnvironmentController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await getEnvironment(data);
|
||||||
|
|
||||||
|
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 "Environment Not found for the User":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Environment Not found for the User",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
CreateLineItems,
|
||||||
|
DeleteLayer,
|
||||||
|
DeleteLineItems,
|
||||||
|
DeleteLinePoints,
|
||||||
|
GetLinesService,
|
||||||
|
UpdateLineItems,
|
||||||
|
} from "../../../../shared/services/builder/lineService.ts";
|
||||||
|
|
||||||
|
export const NewLineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { line, type, layer, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !line || !type || !layer || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
line,
|
||||||
|
type,
|
||||||
|
layer,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await CreateLineItems(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const UpdateLineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { uuid, position, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !uuid || !position || projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await UpdateLineItems({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
uuid,
|
||||||
|
position,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteLineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, line } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !line) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLineItems({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
line,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "line not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "data not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteLayerController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, layer } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !layer) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLayer({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
layer,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "layer not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "data not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DeleteLinePointsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, uuid } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !uuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLinePoints({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
uuid,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Line not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "data not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetLinesController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetLinesService({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,327 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
deleteAssetModel,
|
||||||
|
getFloorItems,
|
||||||
|
replaceEventDatas,
|
||||||
|
setAssetModel,
|
||||||
|
updateAssetPositionRotation,
|
||||||
|
} from "../../../../shared/services/builder/assetService.ts";
|
||||||
|
|
||||||
|
export const CreateAssetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
eventData,
|
||||||
|
modelfileID,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!isLocked ||
|
||||||
|
!isVisible ||
|
||||||
|
!position ||
|
||||||
|
!rotation ||
|
||||||
|
!modelfileID ||
|
||||||
|
!modelName ||
|
||||||
|
!projectId ||
|
||||||
|
!modelUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
eventData,
|
||||||
|
modelfileID,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
};
|
||||||
|
const result = await setAssetModel(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Updated successfully":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Model stored successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteAssetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { modelUuid, modelName, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !modelUuid || !projectId || !modelName) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteAssetModel({
|
||||||
|
organization,
|
||||||
|
modelName,
|
||||||
|
modelUuid,
|
||||||
|
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 "model not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Model not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Failed to archive asset":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Failed to archive asset",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Asset Deleted successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetAssetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await getFloorItems({
|
||||||
|
organization,
|
||||||
|
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 "floorItems not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "floorItems not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ReplaceEventDataController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { modelUuid, eventData, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !modelUuid || !eventData) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await replaceEventDatas({
|
||||||
|
modelUuid,
|
||||||
|
organization,
|
||||||
|
eventData,
|
||||||
|
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 "Model not for this UUID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Model not for this UUID",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ message: "Data updated successfully" });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AssetUpdatePosRotController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!isLocked ||
|
||||||
|
!isVisible ||
|
||||||
|
!position ||
|
||||||
|
!rotation ||
|
||||||
|
!modelName ||
|
||||||
|
!projectId ||
|
||||||
|
!modelUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await updateAssetPositionRotation({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Asset not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Asset not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ message: "Asset updated successfully" });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { Request, Response } from "express";
|
import { Response } from "express";
|
||||||
|
|
||||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
import {
|
import {
|
||||||
GetCamers,
|
GetCamers,
|
||||||
|
onlineActiveDatas,
|
||||||
SetCamera,
|
SetCamera,
|
||||||
} from "../../../../shared/services/builder/cameraService.ts";
|
} from "../../../../shared/services/builder/cameraService.ts";
|
||||||
|
|
||||||
@@ -11,11 +12,10 @@ export const SetNewCamera = async (
|
|||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, role, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { position, target, rotation, projectId, versionId } = req.body;
|
const { position, target, rotation, projectId, versionId } = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
!role ||
|
|
||||||
!userId ||
|
!userId ||
|
||||||
!position ||
|
!position ||
|
||||||
!target ||
|
!target ||
|
||||||
@@ -35,7 +35,6 @@ export const SetNewCamera = async (
|
|||||||
projectId,
|
projectId,
|
||||||
versionId,
|
versionId,
|
||||||
organization,
|
organization,
|
||||||
role,
|
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
const result = await SetCamera(data);
|
const result = await SetCamera(data);
|
||||||
@@ -76,8 +75,9 @@ export const CameraList = async (
|
|||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, role, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !role || !userId) {
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -85,8 +85,8 @@ export const CameraList = async (
|
|||||||
}
|
}
|
||||||
const result = await GetCamers({
|
const result = await GetCamers({
|
||||||
organization,
|
organization,
|
||||||
role,
|
|
||||||
userId,
|
userId,
|
||||||
|
projectId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -113,3 +113,41 @@ export const CameraList = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const ActiveOnlineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
if (!organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await onlineActiveDatas({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { Request, Response } from "express";
|
import { Response } from "express";
|
||||||
import { WallItems } from "../../../../shared/services/builder/wallService.ts";
|
import { WallItems } from "../../../../shared/services/builder/wallService.ts";
|
||||||
import { error } from "console";
|
import { error } from "console";
|
||||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
export const WallSetup = async (
|
export const WallSetup = async (
|
||||||
req: AuthenticatedRequest,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
@@ -18,7 +17,6 @@ export const WallSetup = async (
|
|||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
// versionId
|
|
||||||
projectId,
|
projectId,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
if (
|
if (
|
||||||
@@ -29,10 +27,10 @@ export const WallSetup = async (
|
|||||||
!projectId ||
|
!projectId ||
|
||||||
!csgscale ||
|
!csgscale ||
|
||||||
!csgposition ||
|
!csgposition ||
|
||||||
// !versionId ||
|
|
||||||
!quaternion ||
|
!quaternion ||
|
||||||
!scale ||
|
!scale ||
|
||||||
!organization
|
!organization ||
|
||||||
|
!userId
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required!",
|
message: "All fields are required!",
|
||||||
@@ -42,7 +40,6 @@ export const WallSetup = async (
|
|||||||
const result = await WallItems.setWallItems({
|
const result = await WallItems.setWallItems({
|
||||||
projectId,
|
projectId,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
// versionId,
|
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
type,
|
type,
|
||||||
@@ -51,13 +48,17 @@ export const WallSetup = async (
|
|||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
organization,
|
organization,
|
||||||
|
userId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "Updated successfully":
|
case "Updated successfully":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
case "wall Item created successfully":
|
case "wall Item created successfully":
|
||||||
res.status(200).json(result.data);
|
res.status(201).json(result.data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json(error);
|
res.status(500).json(error);
|
||||||
@@ -75,9 +76,9 @@ export const WallGet = async (
|
|||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, role, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId } = req.params;
|
||||||
if (!organization || !role || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -85,21 +86,21 @@ export const WallGet = async (
|
|||||||
}
|
}
|
||||||
const result = await WallItems.getWallItems({
|
const result = await WallItems.getWallItems({
|
||||||
organization,
|
organization,
|
||||||
role,
|
|
||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "wallitems not found":
|
case "wallitems not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "wallitems not found",
|
message: "wallitems not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json(result.data);
|
||||||
WallItems: result.data,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
@@ -118,16 +119,9 @@ export const WallDelete = async (
|
|||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, role, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, modelName, modelUuid } = req.body;
|
const { projectId, modelName, modelUuid } = req.body;
|
||||||
if (
|
if (!organization || !userId || !projectId || !modelName || !modelUuid) {
|
||||||
!organization ||
|
|
||||||
!role ||
|
|
||||||
!userId ||
|
|
||||||
!projectId ||
|
|
||||||
!modelName ||
|
|
||||||
!modelUuid
|
|
||||||
) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -135,7 +129,6 @@ export const WallDelete = async (
|
|||||||
}
|
}
|
||||||
const result = await WallItems.deleteWallItems({
|
const result = await WallItems.deleteWallItems({
|
||||||
organization,
|
organization,
|
||||||
role,
|
|
||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
modelName,
|
modelName,
|
||||||
@@ -143,15 +136,16 @@ export const WallDelete = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "model not found":
|
case "model not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "model not found",
|
message: "model not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json(result.data);
|
||||||
message: "WallItem deleted",
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
|
|||||||
@@ -1,61 +1,51 @@
|
|||||||
import { Request, Response } from "express";
|
import { Response } from "express";
|
||||||
|
|
||||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
import {
|
import {
|
||||||
GetCamers,
|
DelZone,
|
||||||
SetCamera,
|
GetZones,
|
||||||
} from "../../../../shared/services/builder/cameraService.ts";
|
SetZone,
|
||||||
|
SingleZonePanelData,
|
||||||
|
VizZoneDatas,
|
||||||
|
ZoneData,
|
||||||
|
} from "../../../../shared/services/builder/zoneService.ts";
|
||||||
|
|
||||||
export const SetNewCamera = async (
|
export const CreateZoneController = async (
|
||||||
req: AuthenticatedRequest,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, role, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { position, target, rotation, projectId, versionId } = req.body;
|
const { zoneData, projectId } = req.body;
|
||||||
if (
|
if (!organization || !userId || !zoneData || !projectId) {
|
||||||
!organization ||
|
|
||||||
!role ||
|
|
||||||
!userId ||
|
|
||||||
!position ||
|
|
||||||
!target ||
|
|
||||||
!rotation ||
|
|
||||||
!projectId ||
|
|
||||||
!versionId
|
|
||||||
) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = {
|
const data = {
|
||||||
position,
|
zoneData,
|
||||||
target,
|
|
||||||
rotation,
|
|
||||||
projectId,
|
projectId,
|
||||||
versionId,
|
|
||||||
organization,
|
organization,
|
||||||
role,
|
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
const result = await SetCamera(data);
|
const result = await SetZone(data);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "Project not found":
|
case "User not found":
|
||||||
res.status(404).json({
|
res.status(200).json({
|
||||||
message: "Project not found",
|
message: "User not found",
|
||||||
TrashDatas: [],
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "zone updated":
|
||||||
case "Update Success":
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
TrashDatas: result.data,
|
message: "zone updated",
|
||||||
|
ZoneData: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
TrashDatas: result.data,
|
message: "zone created",
|
||||||
|
ZoneData: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -71,29 +61,35 @@ export const SetNewCamera = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const CameraList = async (
|
export const DeleteZoneController = async (
|
||||||
req: AuthenticatedRequest,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, role, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !role || !userId) {
|
const { zoneId, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !zoneId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await GetCamers({
|
const result = await DelZone({
|
||||||
organization,
|
organization,
|
||||||
role,
|
zoneId,
|
||||||
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "Project not found":
|
case "User not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Project not found",
|
message: "User not found",
|
||||||
TrashDatas: [],
|
});
|
||||||
|
break;
|
||||||
|
case "Invalid zone ID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
@@ -113,3 +109,186 @@ export const CameraList = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const GetZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetZones({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Invalid zone":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const VizZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await VizZoneDatas({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Zone not found for the UUID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ZoneDataController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, zoneId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId || !zoneId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await ZoneData({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
zoneId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SingleZonePanelController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, zoneId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId || !zoneId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SingleZonePanelData({
|
||||||
|
organization,
|
||||||
|
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 UUID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ export const GetTrashList = async (
|
|||||||
const result = await TrashDatas({ organization, role, userId });
|
const result = await TrashDatas({ organization, role, userId });
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Trash is Empty":
|
case "Trash is Empty":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Trash is Empty",
|
message: "Trash is Empty",
|
||||||
@@ -69,6 +74,11 @@ export const RestoreTrash = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Project not found":
|
case "Project not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
@@ -97,3 +107,59 @@ export const RestoreTrash = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const DeleteTrash = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, role, userId } = req.user || {};
|
||||||
|
const { projectId } = req.query as {
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
if (!organization || !projectId || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await RestoreTrashData({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
role,
|
||||||
|
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 "Project Trash Delete unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Trash Delete unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Trash Project Restored successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Trash Project Restored successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,260 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddWidget,
|
||||||
|
GetWidget,
|
||||||
|
UpdateWidget,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
CreateZoneController,
|
||||||
|
DeleteZoneController,
|
||||||
|
GetZoneController,
|
||||||
|
SingleZonePanelController,
|
||||||
|
VizZoneController,
|
||||||
|
ZoneDataController,
|
||||||
|
} from "../../v1Controllers/builderController/v1zoneController.ts";
|
||||||
|
|
||||||
|
const v1Zone = express.Router();
|
||||||
|
|
||||||
|
//Zone-Page
|
||||||
|
v1Zone.post(
|
||||||
|
"/zones",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
CreateZoneController
|
||||||
|
);
|
||||||
|
v1Zone.patch(
|
||||||
|
"/zones/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeleteZoneController
|
||||||
|
);
|
||||||
|
|
||||||
|
//viz
|
||||||
|
v1Zone.get(
|
||||||
|
"/zones/visualization/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
VizZoneController
|
||||||
|
);
|
||||||
|
|
||||||
|
//getzones
|
||||||
|
v1Zone.get(
|
||||||
|
"/zones/:projectId/:zoneId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
ZoneDataController
|
||||||
|
);
|
||||||
|
// viz
|
||||||
|
v1Zone.get(
|
||||||
|
"/zones/panel/:projectId/:zoneId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
SingleZonePanelController
|
||||||
|
);
|
||||||
|
v1Zone.get(
|
||||||
|
"/zones/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
GetZoneController
|
||||||
|
);
|
||||||
|
export default v1Zone;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AssetUpdatePosRotController,
|
||||||
|
CreateAssetController,
|
||||||
|
GetAssetController,
|
||||||
|
ReplaceEventDataController,
|
||||||
|
} from "../../v1Controllers/builderController/v1assetController.ts";
|
||||||
|
|
||||||
|
const v1Asset = express.Router();
|
||||||
|
|
||||||
|
//Asset-Page
|
||||||
|
v1Asset.post(
|
||||||
|
"/setAsset",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
CreateAssetController
|
||||||
|
);
|
||||||
|
v1Asset.patch(
|
||||||
|
"/updateFloorAssetPositions",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
AssetUpdatePosRotController
|
||||||
|
);
|
||||||
|
v1Asset.get(
|
||||||
|
"/floorAssets/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
GetAssetController
|
||||||
|
);
|
||||||
|
v1Asset.patch(
|
||||||
|
"/updateEventData",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
ReplaceEventDataController
|
||||||
|
);
|
||||||
|
export default v1Asset;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
ActiveOnlineController,
|
||||||
|
CameraList,
|
||||||
|
SetNewCamera,
|
||||||
|
} from "../../v1Controllers/builderController/v1cameraController.ts";
|
||||||
|
|
||||||
|
const v1Camera = express.Router();
|
||||||
|
|
||||||
|
//Camera-Page
|
||||||
|
v1Camera.post(
|
||||||
|
"/setCamera",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
SetNewCamera
|
||||||
|
);
|
||||||
|
v1Camera.get(
|
||||||
|
"/activeCameras",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
ActiveOnlineController
|
||||||
|
);
|
||||||
|
v1Camera.get(
|
||||||
|
"/cameras/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
CameraList
|
||||||
|
);
|
||||||
|
|
||||||
|
export default v1Camera;
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteLayerController,
|
||||||
|
DeleteLineController,
|
||||||
|
DeleteLinePointsController,
|
||||||
|
GetLinesController,
|
||||||
|
NewLineController,
|
||||||
|
UpdateLineController,
|
||||||
|
} from "../../v1Controllers/builderController/v1LineController.ts";
|
||||||
|
|
||||||
|
const v1Line = express.Router();
|
||||||
|
|
||||||
|
//Line-Page
|
||||||
|
v1Line.post(
|
||||||
|
"/lines",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
NewLineController
|
||||||
|
);
|
||||||
|
v1Line.post(
|
||||||
|
"/points",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
UpdateLineController
|
||||||
|
);
|
||||||
|
v1Line.patch(
|
||||||
|
"/layers/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeleteLayerController
|
||||||
|
);
|
||||||
|
v1Line.patch(
|
||||||
|
"/lines/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeleteLineController
|
||||||
|
);
|
||||||
|
v1Line.patch(
|
||||||
|
"/points/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeleteLinePointsController
|
||||||
|
);
|
||||||
|
v1Line.get(
|
||||||
|
"/lines/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
GetLinesController
|
||||||
|
);
|
||||||
|
export default v1Line;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
WallDelete,
|
||||||
|
WallGet,
|
||||||
|
WallSetup,
|
||||||
|
} from "../../v1Controllers/builderController/v1wallController.ts";
|
||||||
|
|
||||||
|
const v1Wall = express.Router();
|
||||||
|
|
||||||
|
//Wall-Page
|
||||||
|
v1Wall.post(
|
||||||
|
"/walls",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
WallSetup
|
||||||
|
);
|
||||||
|
v1Wall.patch(
|
||||||
|
"/walls/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
WallDelete
|
||||||
|
);
|
||||||
|
v1Wall.get(
|
||||||
|
"/walls/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
WallGet
|
||||||
|
);
|
||||||
|
export default v1Wall;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import express from "express";
|
|||||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||||
import {
|
import {
|
||||||
|
DeleteTrash,
|
||||||
GetTrashList,
|
GetTrashList,
|
||||||
RestoreTrash,
|
RestoreTrash,
|
||||||
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
||||||
@@ -21,4 +22,11 @@ v1TrashRoutes.patch(
|
|||||||
// authorizedRoles("Admin", "User"),
|
// authorizedRoles("Admin", "User"),
|
||||||
RestoreTrash
|
RestoreTrash
|
||||||
);
|
);
|
||||||
|
|
||||||
|
v1TrashRoutes.patch(
|
||||||
|
"/Trash/Delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeleteTrash
|
||||||
|
);
|
||||||
export default v1TrashRoutes;
|
export default v1TrashRoutes;
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteFloatController,
|
||||||
|
DuplicateFloatController,
|
||||||
|
FloatAddController,
|
||||||
|
GetFloatController,
|
||||||
|
SingleFloatController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1floatWidgetController.ts";
|
||||||
|
|
||||||
|
const v1FloatWidget = express.Router();
|
||||||
|
|
||||||
|
//floatWidget-Page
|
||||||
|
v1FloatWidget.post(
|
||||||
|
"/floatWidget/save",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
FloatAddController
|
||||||
|
);
|
||||||
|
v1FloatWidget.patch(
|
||||||
|
"/floatWidget/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeleteFloatController
|
||||||
|
);
|
||||||
|
v1FloatWidget.get(
|
||||||
|
"/floatWidgets/:zoneId/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
GetFloatController
|
||||||
|
);
|
||||||
|
v1FloatWidget.get(
|
||||||
|
"/floatWidget/:floatWidgetId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
SingleFloatController
|
||||||
|
);
|
||||||
|
v1FloatWidget.post(
|
||||||
|
"/floatWidget/duplicate",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DuplicateFloatController
|
||||||
|
);
|
||||||
|
export default v1FloatWidget;
|
||||||
37
src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts
Normal file
37
src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddTemplateController,
|
||||||
|
AddTemToZoneController,
|
||||||
|
GetTemplateController,
|
||||||
|
TemplateDeleteController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1templateController.ts";
|
||||||
|
|
||||||
|
const v1Template = express.Router();
|
||||||
|
|
||||||
|
//template-Page
|
||||||
|
v1Template.post(
|
||||||
|
"/template/save",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
AddTemplateController
|
||||||
|
);
|
||||||
|
v1Template.post(
|
||||||
|
"/template/toZone",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
AddTemToZoneController
|
||||||
|
);
|
||||||
|
v1Template.get(
|
||||||
|
"/template/data/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
GetTemplateController
|
||||||
|
);
|
||||||
|
v1Template.patch(
|
||||||
|
"/template/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
TemplateDeleteController
|
||||||
|
);
|
||||||
|
export default v1Template;
|
||||||
31
src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts
Normal file
31
src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddPanelController,
|
||||||
|
ClearPanelController,
|
||||||
|
DeletePanelController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1panelController.ts";
|
||||||
|
|
||||||
|
const v1PanelRoutes = express.Router();
|
||||||
|
|
||||||
|
//panel-Page
|
||||||
|
v1PanelRoutes.post(
|
||||||
|
"/panel/save",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
AddPanelController
|
||||||
|
);
|
||||||
|
v1PanelRoutes.patch(
|
||||||
|
"/panel/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
DeletePanelController
|
||||||
|
);
|
||||||
|
v1PanelRoutes.patch(
|
||||||
|
"/panel/clear",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
ClearPanelController
|
||||||
|
);
|
||||||
|
|
||||||
|
export default v1PanelRoutes;
|
||||||
38
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts
Normal file
38
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Add3dWidgetController,
|
||||||
|
Delete3DwidgetController,
|
||||||
|
Get3DWidgetController,
|
||||||
|
Update3DwidgetController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/widget3Dcontroller.ts";
|
||||||
|
|
||||||
|
const v1Widget3d = express.Router();
|
||||||
|
|
||||||
|
//widget3d-Page
|
||||||
|
v1Widget3d.post(
|
||||||
|
"/widget3d/save",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
Add3dWidgetController
|
||||||
|
);
|
||||||
|
v1Widget3d.patch(
|
||||||
|
"/widget3d/update",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
Update3DwidgetController
|
||||||
|
);
|
||||||
|
v1Widget3d.get(
|
||||||
|
"/widget3d/data/:zoneId/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
Get3DWidgetController
|
||||||
|
);
|
||||||
|
v1Widget3d.patch(
|
||||||
|
"/widget3d/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
Delete3DwidgetController
|
||||||
|
);
|
||||||
|
export default v1Widget3d;
|
||||||
37
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts
Normal file
37
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddWidgetController,
|
||||||
|
GetWidgetController,
|
||||||
|
WidgetDeleteController,
|
||||||
|
WidgetUpdateController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1widgetController.ts";
|
||||||
|
|
||||||
|
const v1Widget = express.Router();
|
||||||
|
|
||||||
|
//widget-Page
|
||||||
|
v1Widget.post(
|
||||||
|
"/widget/save",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
AddWidgetController
|
||||||
|
);
|
||||||
|
v1Widget.patch(
|
||||||
|
"/widget/:widgetID",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
WidgetUpdateController
|
||||||
|
);
|
||||||
|
v1Widget.get(
|
||||||
|
"/widget/data",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
GetWidgetController
|
||||||
|
);
|
||||||
|
v1Widget.patch(
|
||||||
|
"/widget/delete",
|
||||||
|
tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "User"),
|
||||||
|
WidgetDeleteController
|
||||||
|
);
|
||||||
|
export default v1Widget;
|
||||||
@@ -25,6 +25,16 @@ import Authrouter from "./V1/v1Routes/authRoutes.ts";
|
|||||||
import v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
import v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
||||||
import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
||||||
import v1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
import v1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
||||||
|
import v1Asset from "./V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts";
|
||||||
|
import v1Camera from "./V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts";
|
||||||
|
import v1Line from "./V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts";
|
||||||
|
import v1Wall from "./V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts";
|
||||||
|
import v1Zone from "./V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts";
|
||||||
|
import v1FloatWidget from "./V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts";
|
||||||
|
import v1PanelRoutes from "./V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts";
|
||||||
|
import v1Template from "./V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts";
|
||||||
|
import v1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts";
|
||||||
|
import v1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
||||||
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||||
redis;
|
redis;
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -94,9 +104,19 @@ app.use("/api/v1", trashRouter);
|
|||||||
app.use("/api/v1", homePageRouter);
|
app.use("/api/v1", homePageRouter);
|
||||||
|
|
||||||
//New versions--based on the token and role based
|
//New versions--based on the token and role based
|
||||||
app.use("/api/v2", Authrouter);
|
app.use("/api/V1", Authrouter);
|
||||||
app.use("/api/v2", v1projectRouter);
|
app.use("/api/V1", v1projectRouter);
|
||||||
app.use("/api/v2", v1TrashRoutes);
|
app.use("/api/V1", v1TrashRoutes);
|
||||||
app.use("/api/v2", v1homeRoutes);
|
app.use("/api/V1", v1homeRoutes);
|
||||||
|
app.use("/api/V1", v1Asset);
|
||||||
|
app.use("/api/V1", v1Camera);
|
||||||
|
app.use("/api/V1", v1Line);
|
||||||
|
app.use("/api/V1", v1Wall);
|
||||||
|
app.use("/api/V1", v1Zone);
|
||||||
|
app.use("/api/V1", v1FloatWidget);
|
||||||
|
app.use("/api/V1", v1PanelRoutes);
|
||||||
|
app.use("/api/V1", v1Template);
|
||||||
|
app.use("/api/V1", v1Widget);
|
||||||
|
app.use("/api/V1", v1Widget3d);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ export class Widget3dService {
|
|||||||
widgetID: id,
|
widgetID: id,
|
||||||
isArchive: false,
|
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 = {
|
const structureData = {
|
||||||
measurements: widgetData?.Data?.measurements,
|
measurements: widgetData?.Data?.measurements,
|
||||||
duration: widgetData?.Data?.duration,
|
duration: widgetData?.Data?.duration,
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export class PanelService {
|
|||||||
|
|
||||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||||
existingZone.panelOrder.indexOf(existingPanel.panelName);
|
existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||||
const zonepanelname = await zoneSchema(organization).updateOne(
|
await zoneSchema(organization).updateOne(
|
||||||
{ _id: existingZone._id },
|
{ _id: existingZone._id },
|
||||||
{ $pull: { panelOrder: existingPanel.panelName } }
|
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ export class WidgetService {
|
|||||||
return res
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
.json({ message: "Widget updated successfully" });
|
.json({ message: "Widget updated successfully" });
|
||||||
|
|
||||||
}
|
}
|
||||||
const newWidget = await widgetSchema(organization).create({
|
const newWidget = await widgetSchema(organization).create({
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Version } from "../Version/versionModel.ts";
|
|||||||
export interface Zone extends Document {
|
export interface Zone extends Document {
|
||||||
zoneName: string;
|
zoneName: string;
|
||||||
zoneId: string;
|
zoneId: string;
|
||||||
zonePoints: [];
|
points: [];
|
||||||
viewPortCenter: [];
|
viewPortCenter: [];
|
||||||
viewPortposition: [];
|
viewPortposition: [];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
|
|||||||
119
src/shared/services/builder/EnvironmentService.ts
Normal file
119
src/shared/services/builder/EnvironmentService.ts
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import environmentModel from "../../V1Models/Environment/environments-Model.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
|
||||||
|
interface EnvironmentInput {
|
||||||
|
roofVisibility: boolean;
|
||||||
|
wallVisibility: boolean;
|
||||||
|
shadowVisibility: boolean;
|
||||||
|
renderDistance: number;
|
||||||
|
limitDistance: boolean;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface GetEnvironmentInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
export const setEnvironment = async (
|
||||||
|
data: EnvironmentInput
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
roofVisibility,
|
||||||
|
wallVisibility,
|
||||||
|
renderDistance,
|
||||||
|
limitDistance,
|
||||||
|
shadowVisibility,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findvalue = await environmentModel(organization).findOne({
|
||||||
|
userId: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (findvalue) {
|
||||||
|
const updatevalue = await environmentModel(organization).findOneAndUpdate(
|
||||||
|
{ userId: userId, projectId: projectId, isArchive: false },
|
||||||
|
{
|
||||||
|
roofVisibility: roofVisibility,
|
||||||
|
wallVisibility: wallVisibility,
|
||||||
|
shadowVisibility: shadowVisibility,
|
||||||
|
renderDistance: renderDistance,
|
||||||
|
limitDistance: limitDistance,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
return { status: "environments updated", data: updatevalue };
|
||||||
|
} else {
|
||||||
|
const newValue = await environmentModel(organization).create({
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
roofVisibility,
|
||||||
|
wallVisibility,
|
||||||
|
shadowVisibility,
|
||||||
|
});
|
||||||
|
return { status: "Success", data: newValue };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getEnvironment = async (
|
||||||
|
data: GetEnvironmentInput
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
|
||||||
|
const findValue = await environmentModel(organization).findOne({
|
||||||
|
userId: userId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!findValue) {
|
||||||
|
return { status: "Environment Not found for the User" };
|
||||||
|
} else {
|
||||||
|
return { status: "Success", data: findValue };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,539 @@
|
|||||||
|
import { Mixed } from "mongoose";
|
||||||
|
import assetModel from "../../V1Models/Builder/assetModel.ts";
|
||||||
|
import EventsDataModel from "../../V1Models/Simulation/eventsDataModel.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
|
||||||
|
interface setAssetInput {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: []; // user ID
|
||||||
|
rotation: object;
|
||||||
|
eventData: Mixed;
|
||||||
|
modelfileID: string;
|
||||||
|
isLocked: boolean;
|
||||||
|
isVisible: boolean;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface AssetUpdate {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: []; // user ID
|
||||||
|
rotation: object;
|
||||||
|
isLocked: boolean;
|
||||||
|
isVisible: boolean;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface DelAssetInput {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface GetAssetInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ReplaceEventInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
eventData: Mixed;
|
||||||
|
modelUuid: string;
|
||||||
|
}
|
||||||
|
export const setAssetModel = async (
|
||||||
|
data: setAssetInput
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
eventData,
|
||||||
|
modelfileID,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findvalue = await assetModel(organization).findOne({
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
userId: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (findvalue) {
|
||||||
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
userId: userId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
modelName: modelName,
|
||||||
|
position: position,
|
||||||
|
rotation: rotation,
|
||||||
|
isVisible: isVisible,
|
||||||
|
isLocked: isLocked,
|
||||||
|
eventData: eventData,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
// return {
|
||||||
|
// success: true,
|
||||||
|
// message: "Model updated successfully",
|
||||||
|
// data: updatevalue,
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
return {
|
||||||
|
status: "Updated successfully",
|
||||||
|
data: updatevalue,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
let assetData: any = {
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
modelfileID,
|
||||||
|
rotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
};
|
||||||
|
|
||||||
|
// if (eventData) {
|
||||||
|
// if (eventData?.type === "Conveyor") {
|
||||||
|
// assetData.eventData = {
|
||||||
|
// type: eventData.type,
|
||||||
|
// // point:undefined,
|
||||||
|
// points: eventData.points,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// assetData.eventData = {
|
||||||
|
// type: eventData.type,
|
||||||
|
// point: eventData.point,
|
||||||
|
// // points: undefined
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
if (eventData) {
|
||||||
|
const typedEventData = eventData as unknown as {
|
||||||
|
type: string;
|
||||||
|
point?: any;
|
||||||
|
points?: any[];
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typedEventData.type === "Conveyor") {
|
||||||
|
assetData.eventData = {
|
||||||
|
type: typedEventData.type,
|
||||||
|
points: typedEventData.points,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
assetData.eventData = {
|
||||||
|
type: typedEventData.type,
|
||||||
|
point: typedEventData.point,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventData) {
|
||||||
|
const typedEventData = eventData as unknown as {
|
||||||
|
type: string;
|
||||||
|
point?: any;
|
||||||
|
points?: any[];
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typedEventData.type === "Conveyor") {
|
||||||
|
assetData.eventData = {
|
||||||
|
type: typedEventData.type,
|
||||||
|
points: typedEventData.points,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
assetData.eventData = {
|
||||||
|
type: typedEventData.type,
|
||||||
|
point: typedEventData.point,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const assetDoc = await assetModel(organization).create(assetData);
|
||||||
|
await assetDoc.save();
|
||||||
|
let assetDatas;
|
||||||
|
const typedEventData = eventData as unknown as { type: string };
|
||||||
|
if (typedEventData && typedEventData.type === "Conveyor") {
|
||||||
|
assetDatas = {
|
||||||
|
projectId: assetDoc.projectId,
|
||||||
|
userId: assetDoc.userId,
|
||||||
|
modelUuid: assetDoc.modelUuid,
|
||||||
|
modelName: assetDoc.modelName,
|
||||||
|
modelfileID: assetDoc.modelfileID,
|
||||||
|
position: assetDoc.position,
|
||||||
|
rotation: assetDoc.rotation,
|
||||||
|
isLocked: assetDoc.isLocked,
|
||||||
|
isVisible: assetDoc.isVisible,
|
||||||
|
eventData: eventData,
|
||||||
|
};
|
||||||
|
} else if (eventData && assetDoc.type === "Vehicle") {
|
||||||
|
assetDatas = {
|
||||||
|
projectId: assetDoc.projectId,
|
||||||
|
userId: assetDoc.userId,
|
||||||
|
modelUuid: assetDoc.modelUuid,
|
||||||
|
modelName: assetDoc.modelName,
|
||||||
|
modelfileID: assetDoc.modelfileID,
|
||||||
|
position: assetDoc.position,
|
||||||
|
rotation: assetDoc.rotation,
|
||||||
|
isLocked: assetDoc.isLocked,
|
||||||
|
isVisible: assetDoc.isVisible,
|
||||||
|
eventData: {
|
||||||
|
points: assetDoc.points,
|
||||||
|
type: assetDoc.type,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (eventData && assetDoc.type === "ArmBot") {
|
||||||
|
assetDatas = {
|
||||||
|
projectId: assetDoc.projectId,
|
||||||
|
userId: assetDoc.userId,
|
||||||
|
modelUuid: assetDoc.modelUuid,
|
||||||
|
modelName: assetDoc.modelName,
|
||||||
|
modelfileID: assetDoc.modelfileID,
|
||||||
|
position: assetDoc.position,
|
||||||
|
rotation: assetDoc.rotation,
|
||||||
|
isLocked: assetDoc.isLocked,
|
||||||
|
isVisible: assetDoc.isVisible,
|
||||||
|
eventData: {
|
||||||
|
points: assetDoc.points,
|
||||||
|
type: assetDoc.type,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (eventData && assetDoc.type === "StaticMachine") {
|
||||||
|
assetDatas = {
|
||||||
|
projectId: assetDoc.projectId,
|
||||||
|
userId: assetDoc.userId,
|
||||||
|
modelUuid: assetDoc.modelUuid,
|
||||||
|
modelName: assetDoc.modelName,
|
||||||
|
modelfileID: assetDoc.modelfileID,
|
||||||
|
position: assetDoc.position,
|
||||||
|
rotation: assetDoc.rotation,
|
||||||
|
isLocked: assetDoc.isLocked,
|
||||||
|
isVisible: assetDoc.isVisible,
|
||||||
|
eventData: {
|
||||||
|
points: assetDoc.points,
|
||||||
|
type: assetDoc.type,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
assetDatas = {
|
||||||
|
projectId: assetDoc.projectId,
|
||||||
|
userId: assetDoc.userId,
|
||||||
|
modelUuid: assetDoc.modelUuid,
|
||||||
|
modelName: assetDoc.modelName,
|
||||||
|
modelfileID: assetDoc.modelfileID,
|
||||||
|
position: assetDoc.position,
|
||||||
|
rotation: assetDoc.rotation,
|
||||||
|
isLocked: assetDoc.isLocked,
|
||||||
|
isVisible: assetDoc.isVisible,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// return {
|
||||||
|
// success: true,
|
||||||
|
// message: "Model created successfully",
|
||||||
|
// data: assetDatas,
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: assetDatas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const deleteAssetModel = async (
|
||||||
|
data: DelAssetInput
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { modelUuid, modelName, organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const asset = await assetModel(organization).findOne({
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!asset) {
|
||||||
|
return {
|
||||||
|
status: "model not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const archivedAsset = await assetModel(organization).findOneAndUpdate(
|
||||||
|
{ modelUuid, modelName, projectId },
|
||||||
|
{ $set: { isArchive: true } },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!archivedAsset) {
|
||||||
|
// return {
|
||||||
|
// success: false,
|
||||||
|
// status: "Failed to archive asset",
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
return {
|
||||||
|
status: "Failed to archive asset",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const updatedEvents = await EventsDataModel(organization).updateMany(
|
||||||
|
{ modelUuid, productId: projectId },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// success: true,
|
||||||
|
// message: "Model deleted successfully",
|
||||||
|
// data: archivedAsset,
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: archivedAsset,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const replaceEventDatas = async (
|
||||||
|
data: ReplaceEventInput
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { modelUuid, organization, eventData, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingModel = await assetModel(organization).findOne({
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingModel) {
|
||||||
|
return { status: "Model not for this UUID" };
|
||||||
|
// return {
|
||||||
|
// success: false,
|
||||||
|
// message: "Model not for this UUID",
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
} else {
|
||||||
|
const typedEventData = eventData as unknown as {
|
||||||
|
speed: number;
|
||||||
|
points?: any[];
|
||||||
|
type?: string;
|
||||||
|
};
|
||||||
|
let speed;
|
||||||
|
|
||||||
|
if (existingModel.type === "Conveyor") {
|
||||||
|
speed = typedEventData?.speed;
|
||||||
|
}
|
||||||
|
const updatedModel = await assetModel(organization).findOneAndUpdate(
|
||||||
|
{ modelUuid, projectId, isArchive: false },
|
||||||
|
{
|
||||||
|
points: typedEventData?.points,
|
||||||
|
// speed: speed,
|
||||||
|
type: typedEventData?.type || existingModel?.type,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
// if (updatedModel)
|
||||||
|
// // return {
|
||||||
|
// // success: true,
|
||||||
|
// // message: "Data updated successfully",
|
||||||
|
// // data: updatedModel,
|
||||||
|
// // organization: organization,
|
||||||
|
// // };
|
||||||
|
// return {
|
||||||
|
// status: "Success",
|
||||||
|
// data: updatedModel,
|
||||||
|
// };
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: updatedModel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const updateAssetPositionRotation = async (
|
||||||
|
data: AssetUpdate
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingAsset = await assetModel(organization).findOne({
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingAsset) {
|
||||||
|
return { status: "Asset not found" };
|
||||||
|
// return res.send("Asset not found");
|
||||||
|
}
|
||||||
|
const updateAsset = await assetModel(organization).updateMany(
|
||||||
|
{
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
modelName: modelName,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
position: position,
|
||||||
|
rotation: rotation,
|
||||||
|
isVisible: isVisible,
|
||||||
|
isLocked: isLocked,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// if (updateAsset)
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: updateAsset,
|
||||||
|
};
|
||||||
|
// return res.status(200).json({ message: "Asset updated successfully" });
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const getFloorItems = async (
|
||||||
|
data: GetAssetInput
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findValues = await assetModel(organization)
|
||||||
|
.find({ isArchive: false })
|
||||||
|
.select("-_id -isArchive");
|
||||||
|
|
||||||
|
if (!findValues || findValues.length === 0) {
|
||||||
|
return { status: "floorItems not found" };
|
||||||
|
// return res.status(200).json({ message: "floorItems not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = findValues.map((item) => {
|
||||||
|
const responseItem: any = {
|
||||||
|
projectId: item.productId,
|
||||||
|
modelUuid: item.modelUuid,
|
||||||
|
modelName: item.modelName,
|
||||||
|
position: item.position,
|
||||||
|
rotation: item.rotation,
|
||||||
|
modelfileID: item.modelfileID,
|
||||||
|
isLocked: item.isLocked,
|
||||||
|
isVisible: item.isVisible,
|
||||||
|
eventData: item.eventData,
|
||||||
|
};
|
||||||
|
return responseItem;
|
||||||
|
});
|
||||||
|
|
||||||
|
// return res.status(200).json(response);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: response,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||||
import cameraModel from "../../V1Models/Builder/cameraModel.ts";
|
import cameraModel from "../../V1Models/Builder/cameraModel.ts";
|
||||||
import { existingProjectById } from "../helpers/v1projecthelperFns.ts";
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IcameraData {
|
interface IcameraData {
|
||||||
userId: string;
|
userId: string;
|
||||||
role: string;
|
|
||||||
position: Object;
|
position: Object;
|
||||||
target: Object;
|
target: Object;
|
||||||
rotation: Object;
|
rotation: Object;
|
||||||
@@ -13,8 +15,12 @@ interface IcameraData {
|
|||||||
}
|
}
|
||||||
interface IgetCameras {
|
interface IgetCameras {
|
||||||
organization: string;
|
organization: string;
|
||||||
userId?: string;
|
projectId: string;
|
||||||
role: string;
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IOnline {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
}
|
}
|
||||||
export const SetCamera = async (
|
export const SetCamera = async (
|
||||||
data: IcameraData
|
data: IcameraData
|
||||||
@@ -22,7 +28,6 @@ export const SetCamera = async (
|
|||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
userId,
|
userId,
|
||||||
role,
|
|
||||||
position,
|
position,
|
||||||
target,
|
target,
|
||||||
rotation,
|
rotation,
|
||||||
@@ -30,6 +35,8 @@ export const SetCamera = async (
|
|||||||
projectId,
|
projectId,
|
||||||
versionId,
|
versionId,
|
||||||
} = data;
|
} = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization,
|
||||||
@@ -38,6 +45,7 @@ export const SetCamera = async (
|
|||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingCamera = await cameraModel(organization).findOne({
|
const existingCamera = await cameraModel(organization).findOne({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existingCamera) {
|
if (existingCamera) {
|
||||||
const updateCamera = await cameraModel(organization).findOneAndUpdate(
|
const updateCamera = await cameraModel(organization).findOneAndUpdate(
|
||||||
@@ -84,10 +92,14 @@ export const SetCamera = async (
|
|||||||
export const GetCamers = async (
|
export const GetCamers = async (
|
||||||
data: IgetCameras
|
data: IgetCameras
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
const { userId, organization, role } = data;
|
const { userId, organization, projectId } = data;
|
||||||
try {
|
try {
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
const findCamera = await cameraModel(organization).findOne({
|
const findCamera = await cameraModel(organization).findOne({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findCamera) {
|
if (!findCamera) {
|
||||||
return { status: "Camera not found" };
|
return { status: "Camera not found" };
|
||||||
@@ -107,17 +119,20 @@ export const GetCamers = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const onlineActiveDatas = async (
|
export const onlineActiveDatas = async (
|
||||||
data: IgetCameras
|
data: IOnline
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
const { organization } = data;
|
const { organization, userId } = data;
|
||||||
try {
|
try {
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
const findactiveUsers = await UsersDataModel(organization).find({
|
const findactiveUsers = await UsersDataModel(organization).find({
|
||||||
activeStatus: "online",
|
activeStatus: "online",
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const cameraDataPromises = findactiveUsers.map(async (activeUser: any) => {
|
const cameraDataPromises = findactiveUsers.map(async (activeUser: any) => {
|
||||||
const cameraData = await cameraModel(organization)
|
const cameraData = await cameraModel(organization)
|
||||||
.findOne({ userId: activeUser._id })
|
.findOne({ userId: activeUser._id, isArchive: false })
|
||||||
.select("position target rotation -_id");
|
.select("position target rotation -_id");
|
||||||
|
|
||||||
if (cameraData) {
|
if (cameraData) {
|
||||||
@@ -137,7 +152,7 @@ export const onlineActiveDatas = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
const cameraDatas = (await Promise.all(cameraDataPromises)).filter(
|
const cameraDatas = (await Promise.all(cameraDataPromises)).filter(
|
||||||
(singledata: any) => singledata !== null
|
(singledata: unknown) => singledata !== null
|
||||||
);
|
);
|
||||||
|
|
||||||
return { status: "Success", data: cameraDatas };
|
return { status: "Success", data: cameraDatas };
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import lineModel from "../../V1Models/Builder/linesModel.ts";
|
import lineModel from "../../V1Models/Builder/linesModel.ts";
|
||||||
|
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
interface ILineItems {
|
interface ILineItems {
|
||||||
organization: string;
|
organization: string;
|
||||||
layer: number;
|
layer: number;
|
||||||
@@ -7,7 +8,11 @@ interface ILineItems {
|
|||||||
projectId: string;
|
projectId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
interface ILineGet {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
interface ILineUpdate {
|
interface ILineUpdate {
|
||||||
organization: string;
|
organization: string;
|
||||||
uuid: number;
|
uuid: number;
|
||||||
@@ -38,6 +43,14 @@ export const CreateLineItems = async (
|
|||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, line, type, layer, projectId, userId } = data;
|
const { organization, line, type, layer, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const newLine = await lineModel(organization).create({
|
const newLine = await lineModel(organization).create({
|
||||||
layer,
|
layer,
|
||||||
line,
|
line,
|
||||||
@@ -62,19 +75,22 @@ export const UpdateLineItems = async (
|
|||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, uuid, position, userId } = data;
|
const { organization, projectId, uuid, position, userId } = data;
|
||||||
const updateResult = await lineModel(organization).updateMany(
|
const UserExists = await existingUser(userId, organization);
|
||||||
{ "line.uuid": uuid, projectId: projectId }, // Filter: Find the line with the given uuid
|
if (!UserExists) return { status: "User not found" };
|
||||||
{ $set: { "line.$.position": position } } // Update the position and type
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
);
|
);
|
||||||
// return {
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
// success: true,
|
const updateResult= await lineModel(organization).updateMany(
|
||||||
// status: "line updated",
|
{ "line.uuid": uuid, projectId: projectId },
|
||||||
// data: { uuid: uuid, position: position },
|
{ $set: { "line.$.position": position } }
|
||||||
// organization: organization,
|
);
|
||||||
// };
|
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
data: { uuid: uuid, position: position },
|
data: updateResult,
|
||||||
};
|
};
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@@ -93,32 +109,32 @@ export const DeleteLineItems = async (
|
|||||||
): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, line, userId } = data;
|
const { organization, projectId, line, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const inputUuids = line.map((item: any) => item.uuid);
|
const inputUuids = line.map((item: any) => item.uuid);
|
||||||
|
|
||||||
const findValue = await lineModel(organization).findOneAndDelete({
|
const findValue = await lineModel(organization).findOneAndDelete(
|
||||||
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
|
{ projectId: projectId, isArchive: false },
|
||||||
});
|
{
|
||||||
|
"line.uuid": { $all: inputUuids },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (!findValue) {
|
if (!findValue) {
|
||||||
return {
|
return {
|
||||||
status: "line not found",
|
status: "line not found",
|
||||||
};
|
};
|
||||||
// return {
|
|
||||||
// success: false,
|
|
||||||
// message: "line not found",
|
|
||||||
// organization: organization,
|
|
||||||
// };
|
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
data: findValue,
|
data: findValue,
|
||||||
};
|
};
|
||||||
// return {
|
|
||||||
// success: true,
|
|
||||||
// message: "line deleted",
|
|
||||||
// data: findValue,
|
|
||||||
// organization: organization,
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@@ -137,16 +153,27 @@ export const DeleteLayer = async (
|
|||||||
): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, layer, userId } = data;
|
const { organization, projectId, layer, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const findValue = await lineModel(organization).find({
|
const findValue = await lineModel(organization).find({
|
||||||
layer: layer,
|
layer: layer,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!findValue) {
|
if (!findValue) {
|
||||||
return { status: "layer not found" };
|
return { status: "layer not found" };
|
||||||
// return { success: false, message: "layer not found" };
|
|
||||||
} else {
|
} else {
|
||||||
await lineModel(organization).deleteMany({ layer: layer });
|
await lineModel(organization).deleteMany(
|
||||||
|
{ projectId: projectId },
|
||||||
|
{ layer: layer }
|
||||||
|
);
|
||||||
|
|
||||||
const updateResult = await lineModel(organization).updateMany(
|
const updateResult = await lineModel(organization).updateMany(
|
||||||
{ layer: { $gt: layer } },
|
{ layer: { $gt: layer } },
|
||||||
@@ -156,12 +183,6 @@ export const DeleteLayer = async (
|
|||||||
status: "Success",
|
status: "Success",
|
||||||
data: updateResult,
|
data: updateResult,
|
||||||
};
|
};
|
||||||
// return {
|
|
||||||
// success: true,
|
|
||||||
// message: "layer deleted",
|
|
||||||
// data: layer,
|
|
||||||
// organization: organization,
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@@ -176,38 +197,68 @@ export const DeleteLayer = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const DeleteLinePoints = async (
|
export const GetLinesService = async (
|
||||||
// data: ILinePointsDelete
|
data: ILineGet
|
||||||
// ): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
// try {
|
try {
|
||||||
// const { organization, projectId, uuid, userId } = data;
|
const { organization, projectId, userId } = data;
|
||||||
// const findValue = await lineModel(organization).deleteMany({
|
const UserExists = await existingUser(userId, organization);
|
||||||
// "line.uuid": uuid,
|
if (!UserExists) return { status: "User not found" };
|
||||||
// });
|
const findValue = await lineModel(organization).find({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!findValue) {
|
||||||
|
return { status: "user not found" };
|
||||||
|
} else {
|
||||||
|
return { status: "Success", data: findValue };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteLinePoints = async (
|
||||||
|
data: ILinePointsDelete
|
||||||
|
): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, uuid, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findValue = await lineModel(organization).deleteMany(
|
||||||
|
{ projectId: projectId, isArchive: false },
|
||||||
|
{
|
||||||
|
"line.uuid": uuid,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// // if (!findValue) {
|
if (!findValue) {
|
||||||
// // return {
|
return { status: "Line not found" };
|
||||||
// // success: false,
|
} else {
|
||||||
// // message: "line not found",
|
return { status: "Success" };
|
||||||
// // organization: organization,
|
}
|
||||||
// // };
|
} catch (error: unknown) {
|
||||||
// // } else {
|
if (error instanceof Error) {
|
||||||
// // return {
|
return {
|
||||||
// // success: true,
|
status: error.message,
|
||||||
// // message: "point deleted",
|
};
|
||||||
// // data: uuid,
|
} else {
|
||||||
// // organization: organization,
|
return {
|
||||||
// // };
|
status: "An unexpected error occurred",
|
||||||
// // }
|
};
|
||||||
// } catch (error: unknown) {
|
}
|
||||||
// if (error instanceof Error) {
|
}
|
||||||
// return {
|
};
|
||||||
// status: error.message,
|
|
||||||
// };
|
|
||||||
// } else {
|
|
||||||
// return {
|
|
||||||
// status: "An unexpected error occurred",
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Request, Response } from "express";
|
|
||||||
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
||||||
|
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IWallSetupData {
|
interface IWallSetupData {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -11,10 +11,10 @@ interface IWallSetupData {
|
|||||||
scale: [];
|
scale: [];
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
}
|
}
|
||||||
interface IWallGet {
|
interface IWallGet {
|
||||||
userId: string;
|
userId: string;
|
||||||
role: string;
|
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@ interface IWallDelete {
|
|||||||
userId: string;
|
userId: string;
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
role: string;
|
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
}
|
}
|
||||||
@@ -30,131 +29,153 @@ interface IWallItemResult {
|
|||||||
data?: Object;
|
data?: Object;
|
||||||
status: string;
|
status: string;
|
||||||
}
|
}
|
||||||
export class WallItems {
|
export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResult> => {
|
||||||
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
|
try {
|
||||||
try {
|
const {
|
||||||
const {
|
userId,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
type,
|
type,
|
||||||
csgposition,
|
csgposition,
|
||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization,
|
||||||
} = data;
|
} = data;
|
||||||
const findvalue = await wallItemModel(organization).findOne({
|
const UserExists = await existingUser(userId, organization);
|
||||||
modelUuid: modelUuid,
|
if (!UserExists) return { status: "User not found" };
|
||||||
});
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findvalue = await wallItemModel(organization).findOne({
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
});
|
||||||
|
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
||||||
{ modelUuid: modelUuid, projectId: projectId },
|
{ modelUuid: modelUuid, projectId: projectId },
|
||||||
{
|
{
|
||||||
modelName,
|
|
||||||
position,
|
|
||||||
type,
|
|
||||||
csgposition,
|
|
||||||
csgscale,
|
|
||||||
quaternion,
|
|
||||||
scale,
|
|
||||||
},
|
|
||||||
{ new: true } // Return the updated document
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
status: "Updated successfully",
|
|
||||||
data: updatevalue,
|
|
||||||
};
|
|
||||||
// res.status(201).json(updatevalue);
|
|
||||||
} else {
|
|
||||||
const newValue = await wallItemModel(organization).create({
|
|
||||||
modelUuid,
|
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
type,
|
type,
|
||||||
projectId,
|
|
||||||
csgposition,
|
csgposition,
|
||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
});
|
},
|
||||||
return {
|
{ new: true } // Return the updated document
|
||||||
status: "wall Item created successfully",
|
);
|
||||||
data: newValue,
|
return {
|
||||||
};
|
status: "Updated successfully",
|
||||||
// res.status(201).json(newValue);
|
data: updatevalue,
|
||||||
}
|
};
|
||||||
} catch (error: unknown) {
|
// res.status(201).json(updatevalue);
|
||||||
if (error instanceof Error) {
|
} else {
|
||||||
return {
|
const newValue = await wallItemModel(organization).create({
|
||||||
status: error.message,
|
modelUuid,
|
||||||
};
|
modelName,
|
||||||
} else {
|
position,
|
||||||
return {
|
type,
|
||||||
status: "An unexpected error occurred",
|
projectId,
|
||||||
};
|
csgposition,
|
||||||
}
|
csgscale,
|
||||||
}
|
quaternion,
|
||||||
}
|
scale,
|
||||||
static async getWallItems(data: IWallGet) {
|
|
||||||
try {
|
|
||||||
const { organization, role, userId, projectId } = data;
|
|
||||||
|
|
||||||
const findValue = await wallItemModel(organization).find();
|
|
||||||
if (!findValue) {
|
|
||||||
return {
|
|
||||||
status: "wallitems not found",
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: "Success",
|
|
||||||
data: findValue,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error: unknown) {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
return {
|
|
||||||
status: error.message,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: "An unexpected error occurred",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> {
|
|
||||||
try {
|
|
||||||
const { modelUuid, modelName, organization, userId, projectId, role } =
|
|
||||||
data;
|
|
||||||
|
|
||||||
const findValue = await wallItemModel(organization).findOneAndDelete({
|
|
||||||
modelUuid: modelUuid,
|
|
||||||
modelName: modelName,
|
|
||||||
projectId: projectId,
|
|
||||||
});
|
});
|
||||||
if (!findValue) {
|
return {
|
||||||
return {
|
status: "wall Item created successfully",
|
||||||
status: "model not found",
|
data: newValue,
|
||||||
};
|
};
|
||||||
} else {
|
// res.status(201).json(newValue);
|
||||||
return {
|
}
|
||||||
status: "Success",
|
} catch (error: unknown) {
|
||||||
data: findValue,
|
if (error instanceof Error) {
|
||||||
};
|
return {
|
||||||
}
|
status: error.message,
|
||||||
} catch (error: unknown) {
|
};
|
||||||
if (error instanceof Error) {
|
} else {
|
||||||
return {
|
return {
|
||||||
status: error.message,
|
status: "An unexpected error occurred",
|
||||||
};
|
};
|
||||||
} else {
|
}
|
||||||
return {
|
}
|
||||||
status: "An unexpected error occurred",
|
}
|
||||||
};
|
export const getWallItems = async (data: IWallGet) => {
|
||||||
}
|
try {
|
||||||
|
const { organization, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findValue = await wallItemModel(organization).find({
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!findValue) {
|
||||||
|
return {
|
||||||
|
status: "wallitems not found",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: findValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const deleteWallItems = async (data: IWallDelete): Promise<IWallItemResult> => {
|
||||||
|
try {
|
||||||
|
const { modelUuid, modelName, organization, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findValue = await wallItemModel(organization).findOneAndDelete({
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
modelName: modelName,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!findValue) {
|
||||||
|
return {
|
||||||
|
status: "model not found",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: findValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,396 @@
|
|||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
|
||||||
|
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
|
||||||
|
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
|
||||||
|
import templateModel from "../../V1Models/Vizualization/templatemodel.ts";
|
||||||
|
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
||||||
|
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface ISetZone {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
zoneData: {
|
||||||
|
zoneId: string;
|
||||||
|
points: [];
|
||||||
|
zoneName: string;
|
||||||
|
layer: number;
|
||||||
|
viewPortCenter: [];
|
||||||
|
viewPortposition: [];
|
||||||
|
};
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IZone {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
zoneId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IVizZone {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
interface IGetZones {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, zoneData, userId } = data;
|
||||||
|
const zoneId = zoneData.zoneId;
|
||||||
|
const points = zoneData.points;
|
||||||
|
const zoneName = zoneData.zoneName;
|
||||||
|
const layer = zoneData.layer;
|
||||||
|
const viewPortCenter = zoneData.viewPortCenter;
|
||||||
|
const viewPortposition = zoneData.viewPortposition;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findZoneId = await zoneModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (findZoneId) {
|
||||||
|
const updateZone = await zoneModel(organization)
|
||||||
|
.findOneAndUpdate(
|
||||||
|
{ zoneId: zoneId, projectId: projectId, isArchive: false },
|
||||||
|
{
|
||||||
|
points: points,
|
||||||
|
viewPortposition: viewPortposition,
|
||||||
|
viewPortCenter: viewPortCenter,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
)
|
||||||
|
.select("-_id -__v");
|
||||||
|
return { status: "zone updated", data: updateZone };
|
||||||
|
} else {
|
||||||
|
const zoneCreate = await zoneModel(organization).create({
|
||||||
|
zoneId,
|
||||||
|
createdBy: userId,
|
||||||
|
projectId,
|
||||||
|
zoneName: zoneName,
|
||||||
|
points,
|
||||||
|
layer,
|
||||||
|
viewPortCenter,
|
||||||
|
viewPortposition,
|
||||||
|
});
|
||||||
|
const createdZone = await zoneModel(organization)
|
||||||
|
.findById(zoneCreate._id)
|
||||||
|
.select("-_id -__v");
|
||||||
|
return { status: "Success", data: createdZone };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, zoneId, projectId } = data;
|
||||||
|
const findZoneId = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
if (findZoneId) {
|
||||||
|
const deleteZone = await zoneModel(organization)
|
||||||
|
.findOneAndDelete({
|
||||||
|
zoneId: zoneId,
|
||||||
|
createdBy: userId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("-_id -__v");
|
||||||
|
if (deleteZone) {
|
||||||
|
const panels = await panelModel(organization).find({
|
||||||
|
zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allWidgetIds = panels.reduce((ids: string[], panel: any) => {
|
||||||
|
return ids.concat(panel.widgets || []);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
await widgetModel(organization).updateMany(
|
||||||
|
{ _id: { $in: allWidgetIds } },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
|
||||||
|
await panelModel(organization).updateMany(
|
||||||
|
{ zoneId, isArchive: false },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
widget3dModel(organization).updateMany(
|
||||||
|
{ zoneId, isArchive: false },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
),
|
||||||
|
templateModel(organization).updateMany(
|
||||||
|
{ zoneId, isArchive: false },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
),
|
||||||
|
floatWidgetModel(organization).updateMany(
|
||||||
|
{ zoneId, isArchive: false },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: deleteZone,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "Invalid zone ID",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetZones = async (data: IGetZones): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const findZoneId = await zoneModel(organization)
|
||||||
|
.find({ projectId: projectId, isArchive: false })
|
||||||
|
.select(
|
||||||
|
"zoneId zoneName layer points viewPortCenter viewPortposition -_id"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!findZoneId) {
|
||||||
|
return { status: "Invalid zone" };
|
||||||
|
}
|
||||||
|
return { status: "Success", data: findZoneId };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ZoneData = async (data: IZone): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId, zoneId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const findZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (findZone)
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: findZone,
|
||||||
|
};
|
||||||
|
else {
|
||||||
|
return { status: "Zone not found" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId, zoneId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingZone = await zoneModel(organization)
|
||||||
|
.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select(
|
||||||
|
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points"
|
||||||
|
);
|
||||||
|
if (!existingZone) {
|
||||||
|
return { status: "Zone not found for the UUID" };
|
||||||
|
} else {
|
||||||
|
const panelData = await panelModel(organization).find({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const zoneName = existingZone.zoneName as string;
|
||||||
|
|
||||||
|
const widgets = await Promise.all(
|
||||||
|
panelData.map(async (data) => {
|
||||||
|
const widgetDataArray = await widgetModel(organization).find({
|
||||||
|
panelID: data._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return widgetDataArray.map((widgetData) => ({
|
||||||
|
id: widgetData.widgetID,
|
||||||
|
type: widgetData.elementType,
|
||||||
|
title: widgetData.widgetName,
|
||||||
|
panel: widgetData.widgetside,
|
||||||
|
data: widgetData.Data || [],
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const flattenedWidgets = widgets.flat();
|
||||||
|
|
||||||
|
const objectData = {
|
||||||
|
zoneName,
|
||||||
|
viewPortposition: existingZone.viewPortposition,
|
||||||
|
zoneId: existingZone.zoneId,
|
||||||
|
viewPortCenter: existingZone.viewPortCenter,
|
||||||
|
activeSides: existingZone.panelOrder || [],
|
||||||
|
panelOrder: existingZone.panelOrder || [],
|
||||||
|
lockedPanels: existingZone.lockedPanel || [],
|
||||||
|
points: existingZone.points || [],
|
||||||
|
widgets: flattenedWidgets,
|
||||||
|
};
|
||||||
|
|
||||||
|
return { status: "Success", data: objectData };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingZones = await zoneModel(organization)
|
||||||
|
.find({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select(
|
||||||
|
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points"
|
||||||
|
);
|
||||||
|
if (!existingZones) {
|
||||||
|
return { status: "Zone not found for the UUID" };
|
||||||
|
} else {
|
||||||
|
const response = await Promise.all(
|
||||||
|
existingZones.map(async (zone) => {
|
||||||
|
const panelData = await panelModel(organization).find({
|
||||||
|
zoneId: zone._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const widgets = await Promise.all(
|
||||||
|
panelData.map(async (panel) => {
|
||||||
|
const widgetDataArray = await widgetModel(organization).find({
|
||||||
|
panelID: panel._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return widgetDataArray.map((widget) => ({
|
||||||
|
id: widget.widgetID,
|
||||||
|
type: widget.elementType,
|
||||||
|
title: widget.widgetName,
|
||||||
|
panel: widget.widgetside,
|
||||||
|
data: widget.Data || [],
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
zoneName: zone.zoneName,
|
||||||
|
zoneId: zone.zoneId,
|
||||||
|
viewPortposition: zone.viewPortposition,
|
||||||
|
viewPortCenter: zone.viewPortCenter,
|
||||||
|
activeSides: zone.panelOrder || [],
|
||||||
|
panelOrder: zone.panelOrder || [],
|
||||||
|
lockedPanels: zone.lockedPanel || [],
|
||||||
|
points: zone.points || [],
|
||||||
|
widgets: widgets.flat(),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return { status: "Success", data: response };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ export const existingUser = async (userId: string, organization: string) => {
|
|||||||
console.log("Invalid ObjectId format");
|
console.log("Invalid ObjectId format");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const userData = await userModel(organization).findOne({
|
const userData = await userModel(organization).findOne({ _id: userId });
|
||||||
_id: userId,
|
|
||||||
});
|
|
||||||
return userData;
|
return userData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import projectModel from "../../model/project/project-model.ts";
|
import projectModel from "../../model/project/project-model.ts";
|
||||||
import userModel from "../../model/user-Model.ts";
|
import userModel from "../../model/user-Model.ts";
|
||||||
import { Types } from "mongoose";
|
|
||||||
import versionModel from "../../model/version/versionModel.ts";
|
import versionModel from "../../model/version/versionModel.ts";
|
||||||
import {
|
import {
|
||||||
existingProject,
|
existingProject,
|
||||||
@@ -98,10 +97,12 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
|
|||||||
if (!existingUser) return { status: "User not found" };
|
if (!existingUser) return { status: "User not found" };
|
||||||
const projectDatas = await projectModel(organization)
|
const projectDatas = await projectModel(organization)
|
||||||
.find({
|
.find({
|
||||||
createdBy:userId,
|
createdBy: userId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("_id projectName createdBy thumbnail createdAt projectUuid createdAt");
|
.select(
|
||||||
|
"_id projectName createdBy thumbnail createdAt projectUuid createdAt"
|
||||||
|
);
|
||||||
if (projectDatas) return { status: "Success", Datas: projectDatas };
|
if (projectDatas) return { status: "Success", Datas: projectDatas };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return { status: error };
|
return { status: error };
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
import projectModel from "../../model/project/project-model.ts";
|
import projectModel from "../../model/project/project-model.ts";
|
||||||
|
import { existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IOrg {
|
interface IOrg {
|
||||||
organization: string;
|
organization: string;
|
||||||
|
userId: string;
|
||||||
}
|
}
|
||||||
interface IRestore {
|
interface IRestore {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
|
userId: string;
|
||||||
}
|
}
|
||||||
export const TrashDatas = async (data: IOrg) => {
|
export const TrashDatas = async (data: IOrg) => {
|
||||||
try {
|
try {
|
||||||
const { organization } = data;
|
const { organization, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
const TrashLists = await projectModel(organization).find({
|
const TrashLists = await projectModel(organization).find({
|
||||||
isArchive: true,
|
isArchive: true,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
@@ -47,7 +51,9 @@ export const TrashDatas = async (data: IOrg) => {
|
|||||||
};
|
};
|
||||||
export const RestoreTrashData = async (data: IRestore) => {
|
export const RestoreTrashData = async (data: IRestore) => {
|
||||||
try {
|
try {
|
||||||
const { projectId, organization } = data;
|
const { projectId, organization, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
const findProject = await projectModel(organization).findOne({
|
const findProject = await projectModel(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: true,
|
isArchive: true,
|
||||||
@@ -64,3 +70,25 @@ export const RestoreTrashData = async (data: IRestore) => {
|
|||||||
return { status: error };
|
return { status: error };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const TrashDelete = async (data: IRestore) => {
|
||||||
|
try {
|
||||||
|
const { projectId, organization, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const findProject = await projectModel(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: true,
|
||||||
|
});
|
||||||
|
if (!findProject) return { status: "Project not found" };
|
||||||
|
const DeleteTrashData = await projectModel(organization).findOneAndUpdate(
|
||||||
|
{ _id: projectId, isArchive: true },
|
||||||
|
{ isDelete: true },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!DeleteTrashData)
|
||||||
|
return { status: "Project Trash Delete unsuccessfull" };
|
||||||
|
return { status: "Trash Project Restored successfully" };
|
||||||
|
} catch (error) {
|
||||||
|
return { status: error };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export const RecentlyAdded = async (data: IRecentData) => {
|
|||||||
try {
|
try {
|
||||||
const { userId, organization, role } = data;
|
const { userId, organization, role } = data;
|
||||||
const userExisting = await existingUser(userId, organization);
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
console.log('userExisting: ', userExisting);
|
||||||
if (!userExisting) return { status: "User not found" };
|
if (!userExisting) return { status: "User not found" };
|
||||||
const userRecentData = await UsersDataModel(organization)
|
const userRecentData = await UsersDataModel(organization)
|
||||||
.findOne({ userId: userId, isArchive: false })
|
.findOne({ userId: userId, isArchive: false })
|
||||||
|
|||||||
390
src/shared/services/visualization/floatWidgetService.ts
Normal file
390
src/shared/services/visualization/floatWidgetService.ts
Normal file
@@ -0,0 +1,390 @@
|
|||||||
|
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
|
||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import { existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
interface IAddFloatData {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
widget: {
|
||||||
|
className: string;
|
||||||
|
id: string;
|
||||||
|
iconName: string;
|
||||||
|
header: string;
|
||||||
|
floatWidgetID: string;
|
||||||
|
position: {};
|
||||||
|
per: string;
|
||||||
|
value: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
zoneId: string;
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
zoneId: string;
|
||||||
|
index: number;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IDelFloat {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
zoneId: string;
|
||||||
|
floatWidgetID: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface ISingleFloat {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
floatWidgetID: string;
|
||||||
|
}
|
||||||
|
interface IGetZoneFloat {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
zoneId: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IDuplicateFloatData {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
widget: {
|
||||||
|
className: string;
|
||||||
|
id: string;
|
||||||
|
iconName: string;
|
||||||
|
header: string;
|
||||||
|
floatWidgetID: string;
|
||||||
|
position: {};
|
||||||
|
per: string;
|
||||||
|
value: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
zoneId: string;
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
zoneId: string;
|
||||||
|
index: number;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widget, zoneId, index, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (existingFloatWidget) {
|
||||||
|
const updateFloatWidget = await floatWidgetModel(
|
||||||
|
organization
|
||||||
|
).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements,
|
||||||
|
duration: widget?.Data?.duration,
|
||||||
|
},
|
||||||
|
header: widget?.header,
|
||||||
|
position: widget?.position,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
upsert: true,
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const floatUpdateDatas = {
|
||||||
|
position: updateFloatWidget.position,
|
||||||
|
index: index,
|
||||||
|
zoneId: zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
return { status: "Widget updated successfully", data: floatUpdateDatas };
|
||||||
|
} else {
|
||||||
|
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||||
|
className: widget.className,
|
||||||
|
iconName: widget.iconName,
|
||||||
|
header: widget.header,
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
position: widget.position,
|
||||||
|
per: widget.per,
|
||||||
|
value: widget.value,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (newFloadWidget) {
|
||||||
|
const floatDatas = {
|
||||||
|
widget: {
|
||||||
|
position: newFloadWidget.position,
|
||||||
|
header: newFloadWidget.header,
|
||||||
|
value: newFloadWidget.value,
|
||||||
|
per: newFloadWidget.per,
|
||||||
|
className: newFloadWidget.className,
|
||||||
|
id: newFloadWidget.floatWidgetID,
|
||||||
|
},
|
||||||
|
zoneId: zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
return { status: "Success", data: floatDatas };
|
||||||
|
}
|
||||||
|
return { status: "Failed to create FloatWidget" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, floatWidgetID, zoneId, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
|
floatWidgetID: floatWidgetID,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!findfloatWidget) return { status: "FloatWidget not found for the Id" };
|
||||||
|
const widgetData = await floatWidgetModel(organization).findByIdAndUpdate(
|
||||||
|
{ _id: findfloatWidget._id, isArchive: false },
|
||||||
|
{ isArchive: true },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (widgetData) {
|
||||||
|
const floatDeleteData = {
|
||||||
|
floatWidgetID: findfloatWidget.floatWidgetID,
|
||||||
|
zoneId: findfloatWidget.zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
return { status: "Success", data: floatDeleteData };
|
||||||
|
}
|
||||||
|
return { status: "FloatWidget not deleted" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DuplicateFloat = async (
|
||||||
|
data: IDuplicateFloatData
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widget, zoneId, index, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (existingFloatWidget) {
|
||||||
|
const updateFloatWidget = await floatWidgetModel(
|
||||||
|
organization
|
||||||
|
).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements,
|
||||||
|
duration: widget?.Data?.duration,
|
||||||
|
},
|
||||||
|
header: widget?.header,
|
||||||
|
position: widget?.position,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
upsert: true,
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!updateFloatWidget) {
|
||||||
|
return { status: "FloatWidget update unsuccessfull" };
|
||||||
|
}
|
||||||
|
const floatUpdateDatas = {
|
||||||
|
position: updateFloatWidget.position,
|
||||||
|
index: index,
|
||||||
|
zoneId: zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
status: "Widget updated successfully",
|
||||||
|
data: floatUpdateDatas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||||
|
className: widget.className,
|
||||||
|
header: widget.header,
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
position: widget.position,
|
||||||
|
per: widget.per,
|
||||||
|
value: widget.value,
|
||||||
|
zoneId: zoneId,
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements,
|
||||||
|
duration: widget?.Data?.duration,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (newFloadWidget) {
|
||||||
|
const floatDatas = {
|
||||||
|
widget: {
|
||||||
|
position: newFloadWidget.position,
|
||||||
|
header: newFloadWidget.header,
|
||||||
|
value: newFloadWidget.value,
|
||||||
|
per: newFloadWidget.per,
|
||||||
|
className: newFloadWidget.className,
|
||||||
|
id: newFloadWidget.floatWidgetID,
|
||||||
|
},
|
||||||
|
zoneId: zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
index: index,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: floatDatas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Failed to duplicate FloatWidget",
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, zoneId, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
|
const widgetData = await floatWidgetModel(organization)
|
||||||
|
.find({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||||
|
if (!widgetData || widgetData.length === 0) {
|
||||||
|
return { status: "All Datas" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedWidgets = widgetData.map((widget) => ({
|
||||||
|
Data: {
|
||||||
|
measurements: widget.Data?.measurements || {},
|
||||||
|
duration: widget.Data?.duration || "1h",
|
||||||
|
},
|
||||||
|
className: widget.className,
|
||||||
|
iconName: widget?.iconName,
|
||||||
|
header: widget.header,
|
||||||
|
id: widget.floatWidgetID,
|
||||||
|
position: widget.position,
|
||||||
|
per: widget.per,
|
||||||
|
value: widget.value,
|
||||||
|
}));
|
||||||
|
return { status: "Success", data: formattedWidgets };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SingleFloatWidget = async (
|
||||||
|
data: ISingleFloat
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, floatWidgetID, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const widgetData = await floatWidgetModel(organization)
|
||||||
|
.findOne({
|
||||||
|
floatWidgetID: floatWidgetID,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||||
|
if (!widgetData || widgetData.length === 0) {
|
||||||
|
return { status: "Widget not found" };
|
||||||
|
}
|
||||||
|
const Datastructure = {
|
||||||
|
measurements: widgetData?.Data?.measurements || {},
|
||||||
|
duration: widgetData?.Data?.duration || "1h",
|
||||||
|
};
|
||||||
|
const header = widgetData?.header;
|
||||||
|
return { status: "Success", data: { Datastructure, header } };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
324
src/shared/services/visualization/panelService.ts
Normal file
324
src/shared/services/visualization/panelService.ts
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
|
||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
||||||
|
import { existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
interface IAddPanel {
|
||||||
|
organization: string;
|
||||||
|
zoneId: string;
|
||||||
|
panelOrder: string[];
|
||||||
|
userId: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IPanel {
|
||||||
|
organization: string;
|
||||||
|
zoneId: string;
|
||||||
|
panelName: string;
|
||||||
|
userId: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface ILockedPanel {
|
||||||
|
organization: string;
|
||||||
|
zoneId: string;
|
||||||
|
lockedPanel: string[];
|
||||||
|
userId: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, zoneId, panelOrder, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
|
await zoneModel(organization).findOneAndUpdate(
|
||||||
|
{ zoneId: zoneId, isArchive: false },
|
||||||
|
{ panelOrder: panelOrder },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
const existingPanels = await panelModel(organization).find({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const existingPanelNames = existingPanels.map(
|
||||||
|
(panel) => panel.panelName as string
|
||||||
|
);
|
||||||
|
|
||||||
|
const missingPanels = panelOrder.filter(
|
||||||
|
(panelName: string) => !existingPanelNames.includes(panelName)
|
||||||
|
);
|
||||||
|
|
||||||
|
const createdPanels = [];
|
||||||
|
for (const panelName of missingPanels) {
|
||||||
|
const newPanel = await panelModel(organization).create({
|
||||||
|
zoneId: zoneId,
|
||||||
|
panelName: panelName,
|
||||||
|
widgets: [],
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
createdPanels.push(newPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createdPanels.length === 0) {
|
||||||
|
return { status: "No new panels were created. All panels already exist" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
|
organization,
|
||||||
|
zoneId,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
if (!zoneAndPanelData) {
|
||||||
|
return zoneAndPanelData;
|
||||||
|
}
|
||||||
|
return { status: "Success", data: zoneAndPanelData };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, zoneId, panelName, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
|
const existingPanel = await panelModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
panelName: panelName,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingPanel) return { status: "Panel Already Deleted" };
|
||||||
|
|
||||||
|
await panelModel(organization).updateOne(
|
||||||
|
{ _id: existingPanel._id, isArchive: false },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
const existingWidgets = await widgetModel(organization).find({
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const widgetData of existingWidgets) {
|
||||||
|
widgetData.isArchive = true;
|
||||||
|
await widgetData.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||||
|
await zoneModel(organization).updateOne(
|
||||||
|
{ _id: existingZone._id },
|
||||||
|
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
|
organization,
|
||||||
|
zoneId,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
if (!zoneAndPanelData) {
|
||||||
|
return zoneAndPanelData;
|
||||||
|
}
|
||||||
|
return { status: "Success", data: zoneAndPanelData };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, zoneId, panelName, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
|
const existingPanel = await panelModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
panelName: panelName,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingPanel) return { status: "Requested Panel not found" };
|
||||||
|
|
||||||
|
const existingWidgets = await widgetModel(organization).find({
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingWidgets.length === 0) return { status: "No widgets to clear" };
|
||||||
|
|
||||||
|
const clearWidgetsofPanel = await widgetModel(organization).updateMany(
|
||||||
|
{ panelID: existingPanel._id, isArchive: false },
|
||||||
|
{ isArchive: true }
|
||||||
|
);
|
||||||
|
const removeWidgetsInPanel = await panelModel(
|
||||||
|
organization
|
||||||
|
).findOneAndUpdate(
|
||||||
|
{ _id: existingPanel._id, isArchive: false },
|
||||||
|
{ $set: { widgets: [] } },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!clearWidgetsofPanel && !removeWidgetsInPanel)
|
||||||
|
return { status: "Failed to clear widgets in panel" };
|
||||||
|
|
||||||
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
|
organization,
|
||||||
|
zoneId,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
if (!zoneAndPanelData) {
|
||||||
|
return zoneAndPanelData;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: zoneAndPanelData,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, zoneId, lockedPanel, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
|
else {
|
||||||
|
const updateLockedPanel = await zoneModel(organization).findOneAndUpdate(
|
||||||
|
{ zoneId: zoneId, isArchive: false },
|
||||||
|
{
|
||||||
|
lockedPanel: lockedPanel,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
|
organization,
|
||||||
|
zoneId,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
if (!zoneAndPanelData) {
|
||||||
|
return zoneAndPanelData;
|
||||||
|
}
|
||||||
|
if (updateLockedPanel) {
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: zoneAndPanelData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { status: "locked panel not updated" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const getZoneAndPanelData = async (
|
||||||
|
organization: string,
|
||||||
|
zoneId: string,
|
||||||
|
projectId: string
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const existingZone = await zoneModel(organization)
|
||||||
|
.findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
})
|
||||||
|
.select(
|
||||||
|
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition"
|
||||||
|
);
|
||||||
|
if (!existingZone) {
|
||||||
|
return { status: "Zone not found" };
|
||||||
|
} else {
|
||||||
|
const panelData = await panelModel(organization).find({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const zoneName = existingZone.zoneName as string;
|
||||||
|
|
||||||
|
const widgets = await Promise.all(
|
||||||
|
panelData.map(async (data) => {
|
||||||
|
const widgetDataArray = await widgetModel(organization).find({
|
||||||
|
panelID: data._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return widgetDataArray.map((widgetData) => ({
|
||||||
|
id: widgetData.widgetID,
|
||||||
|
type: widgetData.elementType,
|
||||||
|
title: widgetData.widgetName,
|
||||||
|
panel: widgetData.widgetside,
|
||||||
|
data: widgetData.Data || [],
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const flattenedWidgets = widgets.flat();
|
||||||
|
|
||||||
|
const objectData = {
|
||||||
|
zoneName,
|
||||||
|
viewPortposition: existingZone.viewPortposition,
|
||||||
|
zoneId: existingZone.zoneId,
|
||||||
|
viewPortCenter: existingZone.viewPortCenter,
|
||||||
|
activeSides: existingZone.panelOrder || [],
|
||||||
|
panelOrder: existingZone.panelOrder || [],
|
||||||
|
lockedPanels: existingZone.lockedPanel || [],
|
||||||
|
points: existingZone.zonePoints || [],
|
||||||
|
widgets: flattenedWidgets,
|
||||||
|
};
|
||||||
|
|
||||||
|
return { data: objectData };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
return { status: "Panel not found" };
|
||||||
|
}
|
||||||
|
};
|
||||||
304
src/shared/services/visualization/templateService.ts
Normal file
304
src/shared/services/visualization/templateService.ts
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
import templateModel from "../../V1Models/Vizualization/templatemodel.ts";
|
||||||
|
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
|
||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
||||||
|
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
|
||||||
|
import { existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
interface IAddTemplate {
|
||||||
|
organization: string;
|
||||||
|
template: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
snapshot: string;
|
||||||
|
panelOrder: [];
|
||||||
|
widgets: [];
|
||||||
|
floatingWidget: [];
|
||||||
|
Widgets3D: [];
|
||||||
|
};
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ITemplateToZone {
|
||||||
|
organization: string;
|
||||||
|
templateID: string;
|
||||||
|
projectId: string;
|
||||||
|
zoneId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ITemplate {
|
||||||
|
organization: string;
|
||||||
|
templateID: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IGetTemplate {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, template, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
|
templateID: template.id,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (existingTemplate) return { status: "TemplateID alreay exists" };
|
||||||
|
const newTemplate = await templateModel(organization).create({
|
||||||
|
templateID: template.id,
|
||||||
|
templateName: template.name,
|
||||||
|
panelOrder: template.panelOrder,
|
||||||
|
widgets: template.widgets,
|
||||||
|
snapshot: template.snapshot,
|
||||||
|
floatWidgets: template.floatingWidget,
|
||||||
|
Widgets3D: template.Widgets3D,
|
||||||
|
});
|
||||||
|
if (newTemplate) {
|
||||||
|
const allTemplateDatas = await templateModel(organization)
|
||||||
|
.find({ isArchive: false })
|
||||||
|
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
||||||
|
|
||||||
|
const formattedTemplates = allTemplateDatas.map(async (data) => ({
|
||||||
|
id: data.templateID,
|
||||||
|
name: data.templateName,
|
||||||
|
panelOrder: data.panelOrder,
|
||||||
|
widgets: data.widgets,
|
||||||
|
floatingWidget: data.floatWidgets,
|
||||||
|
widgets3D: data.Widgets3D,
|
||||||
|
snapshot: data.snapshot,
|
||||||
|
}));
|
||||||
|
return { status: "Success", data: formattedTemplates };
|
||||||
|
}
|
||||||
|
return { status: "Template not saved" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AddTemplateToZone = async (
|
||||||
|
data: ITemplateToZone
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, templateID, projectId, zoneId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone)
|
||||||
|
return {
|
||||||
|
status: "Zone not found ",
|
||||||
|
};
|
||||||
|
|
||||||
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
|
templateID: templateID,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingTemplate)
|
||||||
|
return {
|
||||||
|
status: "TemplateID not found",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (existingZone.panelOrder.length > 0) {
|
||||||
|
existingZone.panelOrder = existingTemplate.panelOrder;
|
||||||
|
await existingZone.save();
|
||||||
|
const archivePanelDatas = await panelModel(organization).find({
|
||||||
|
zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
for (const panelData of archivePanelDatas) {
|
||||||
|
await widgetModel(organization).deleteMany({
|
||||||
|
panelID: panelData._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await panelModel(organization).deleteMany({
|
||||||
|
zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
await floatWidgetModel(organization).deleteMany({
|
||||||
|
zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
existingZone.panelOrder = existingTemplate.panelOrder;
|
||||||
|
await existingZone.save();
|
||||||
|
const existingPanels = await panelModel(organization).find({
|
||||||
|
zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const existingPanelNames = existingPanels.map(
|
||||||
|
(panel) => panel.panelName as string
|
||||||
|
);
|
||||||
|
|
||||||
|
const missingPanels = existingTemplate.panelOrder.filter(
|
||||||
|
(panelName: string) => !existingPanelNames.includes(panelName)
|
||||||
|
);
|
||||||
|
await Promise.all(
|
||||||
|
missingPanels.map((panelName: any) =>
|
||||||
|
panelModel(organization).create({
|
||||||
|
zoneId,
|
||||||
|
panelName,
|
||||||
|
widgets: [],
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const widgetData of existingTemplate.widgets) {
|
||||||
|
const addedExistingPanel = await panelModel(organization).findOne({
|
||||||
|
panelName: widgetData.panel,
|
||||||
|
zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!addedExistingPanel) continue;
|
||||||
|
|
||||||
|
const existingWidget = await widgetModel(organization).findOne({
|
||||||
|
panelID: addedExistingPanel._id,
|
||||||
|
widgetID: widgetData.id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingWidget) continue;
|
||||||
|
|
||||||
|
const newWidget = await widgetModel(organization).create({
|
||||||
|
widgetID: widgetData.id,
|
||||||
|
elementType: widgetData.type,
|
||||||
|
zoneId: zoneId,
|
||||||
|
widgetName: widgetData.widgetName || "Widget",
|
||||||
|
panelID: addedExistingPanel._id,
|
||||||
|
widgetside: widgetData.panel,
|
||||||
|
});
|
||||||
|
addedExistingPanel.widgets.push(newWidget._id);
|
||||||
|
await addedExistingPanel.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const floatData of existingTemplate.floatWidgets) {
|
||||||
|
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
|
floatWidgetID: floatData.id,
|
||||||
|
isArchive: false,
|
||||||
|
zoneId,
|
||||||
|
});
|
||||||
|
if (existingFloatWidget) continue;
|
||||||
|
|
||||||
|
await floatWidgetModel(organization).create({
|
||||||
|
className: floatData.className,
|
||||||
|
header: floatData.header,
|
||||||
|
floatWidgetID: floatData.id,
|
||||||
|
position: floatData.position,
|
||||||
|
per: floatData.per,
|
||||||
|
value: floatData.value,
|
||||||
|
zoneId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const templateZoneDatas = {
|
||||||
|
template: {
|
||||||
|
id: existingTemplate.templateID,
|
||||||
|
name: existingTemplate.templateName,
|
||||||
|
panelOrder: existingTemplate.panelOrder,
|
||||||
|
widgets: existingTemplate.widgets,
|
||||||
|
snapshot: existingTemplate.snapshot,
|
||||||
|
floatingWidget: existingTemplate.floatWidgets,
|
||||||
|
},
|
||||||
|
zoneId: existingZone.zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
|
||||||
|
return { status: "Success", data: templateZoneDatas };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { templateID, projectId, userId, organization } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
|
templateID: templateID,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (existingTemplate) {
|
||||||
|
const newTemplate = await templateModel(organization).updateOne(
|
||||||
|
{ templateID: templateID, isArchive: false, projectId: projectId },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
if (newTemplate) {
|
||||||
|
const TemplateDeleteData = existingTemplate.templateID;
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: TemplateDeleteData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { status: "Template not Deleted" };
|
||||||
|
}
|
||||||
|
return { status: "Template not found" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const templateDatas = await templateModel(organization)
|
||||||
|
.find({ projectId: projectId, isArchive: false })
|
||||||
|
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
||||||
|
if (!templateDatas) return { status: "All Datas" };
|
||||||
|
|
||||||
|
const formattedTemplates = templateDatas.map((data) => ({
|
||||||
|
id: data.templateID,
|
||||||
|
name: data.templateName,
|
||||||
|
panelOrder: data.panelOrder,
|
||||||
|
widgets: data.widgets,
|
||||||
|
floatingWidget: data.floatWidgets,
|
||||||
|
widgets3D: data.Widgets3D,
|
||||||
|
snapshot: data.snapshot,
|
||||||
|
}));
|
||||||
|
return { status: "Success", data: formattedTemplates };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
280
src/shared/services/visualization/widget3dService.ts
Normal file
280
src/shared/services/visualization/widget3dService.ts
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
|
||||||
|
import { existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
interface IWidget3DAdd {
|
||||||
|
organization: string;
|
||||||
|
widget: {
|
||||||
|
id: string;
|
||||||
|
position: [];
|
||||||
|
type: string;
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
projectId: string;
|
||||||
|
zoneId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IWidget3dUpdate {
|
||||||
|
organization: string;
|
||||||
|
id: string;
|
||||||
|
projectId: string;
|
||||||
|
zoneId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IWidgetUpdate {
|
||||||
|
organization: string;
|
||||||
|
id: string;
|
||||||
|
position: [];
|
||||||
|
rotation: [];
|
||||||
|
projectId: string;
|
||||||
|
zoneId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface I3dWidgetGet {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
zoneId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widget, userId, zoneId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
|
widgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existing3Dwidget) {
|
||||||
|
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
widgetID: widget.id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{ position: widget.position },
|
||||||
|
{ upsert: true, new: true }
|
||||||
|
);
|
||||||
|
if (update3dwidget) {
|
||||||
|
return {
|
||||||
|
status: "3dwidget update successfully",
|
||||||
|
};
|
||||||
|
} else return { status: "3dWidget not updated" };
|
||||||
|
} else {
|
||||||
|
const newWidget3d = await widget3dModel(organization).create({
|
||||||
|
type: widget.type,
|
||||||
|
widgetID: widget.id,
|
||||||
|
position: widget.position,
|
||||||
|
zoneId,
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements || {},
|
||||||
|
duration: widget?.Data?.duration || "1h",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (newWidget3d) {
|
||||||
|
const widgemodel3D_Datas = {
|
||||||
|
widget: {
|
||||||
|
id: newWidget3d.widgetID,
|
||||||
|
type: newWidget3d.type,
|
||||||
|
position: newWidget3d.position,
|
||||||
|
},
|
||||||
|
Data: newWidget3d.Data,
|
||||||
|
zoneId: zoneId,
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: widgemodel3D_Datas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { status: "Widget 3d not created" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, id, position, rotation, userId, zoneId, projectId } =
|
||||||
|
data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone)
|
||||||
|
return {
|
||||||
|
status: "Zone not found",
|
||||||
|
};
|
||||||
|
|
||||||
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
|
widgetID: id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existing3Dwidget) {
|
||||||
|
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
widgetID: id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{ position: position, rotation: rotation },
|
||||||
|
{ upsert: true, new: true }
|
||||||
|
);
|
||||||
|
if (update3dwidget) {
|
||||||
|
const updateDatas = {
|
||||||
|
widget: {
|
||||||
|
id: update3dwidget.widgetID,
|
||||||
|
type: update3dwidget.type,
|
||||||
|
position: update3dwidget.position,
|
||||||
|
rotation: update3dwidget.rotation,
|
||||||
|
},
|
||||||
|
zoneId: zoneId,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: updateDatas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { status: "Widget not updated" };
|
||||||
|
} else {
|
||||||
|
return { status: "widget not found" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const Delete3Dwidget = async (
|
||||||
|
data: IWidget3dUpdate
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, id, userId, zoneId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone)
|
||||||
|
return {
|
||||||
|
status: "Zone not found",
|
||||||
|
};
|
||||||
|
|
||||||
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
|
widgetID: id,
|
||||||
|
isArchive: false,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (!existing3Dwidget) {
|
||||||
|
return { status: "3D widget not found for the ID" };
|
||||||
|
}
|
||||||
|
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
widgetID: id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{ isArchive: true },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (updateWidget) {
|
||||||
|
const delete_Datas = {
|
||||||
|
zoneId: zoneId,
|
||||||
|
id: existing3Dwidget.widgetID,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: delete_Datas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { status: "3DWidget delete unsuccessfull" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, zoneId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone)
|
||||||
|
return {
|
||||||
|
status: "Zone not found",
|
||||||
|
};
|
||||||
|
const widgetData = await widget3dModel(organization).find({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!widgetData || widgetData.length === 0) {
|
||||||
|
return { status: "All 3Dwidgets" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const zonebasedWidget = widgetData.map((widget) => ({
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements || {},
|
||||||
|
duration: widget?.Data?.duration || "1h",
|
||||||
|
},
|
||||||
|
type: widget.type,
|
||||||
|
id: widget.widgetID,
|
||||||
|
position: widget.position,
|
||||||
|
rotation: widget?.rotation,
|
||||||
|
}));
|
||||||
|
return { status: "Success", data: zonebasedWidget };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
356
src/shared/services/visualization/widgetService.ts
Normal file
356
src/shared/services/visualization/widgetService.ts
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
interface IWidgetCreate {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
zoneId: string;
|
||||||
|
projectId: string;
|
||||||
|
widget: {
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
panel: string;
|
||||||
|
id: string;
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
interface IWidgetDelete {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
zoneId: string;
|
||||||
|
projectId: string;
|
||||||
|
widgetID: string;
|
||||||
|
}
|
||||||
|
interface IWidgetUpdate {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
zoneId: string;
|
||||||
|
projectId: string;
|
||||||
|
widgetID: string;
|
||||||
|
values: {
|
||||||
|
widgetName: string;
|
||||||
|
widgetSide: string;
|
||||||
|
type: string;
|
||||||
|
Data: {
|
||||||
|
measurement: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
color: string;
|
||||||
|
fontFamily: string;
|
||||||
|
fontStyle: string;
|
||||||
|
fontWeight: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
interface IGetWidget {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
zoneId: string;
|
||||||
|
projectId: string;
|
||||||
|
widgetID: string;
|
||||||
|
}
|
||||||
|
export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widget, userId, zoneId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const existingPanel = await panelModel(organization).findOne({
|
||||||
|
panelName: widget.panel,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingPanel) return { status: "panelName not found" };
|
||||||
|
|
||||||
|
if (existingPanel.panelName === widget.panel) {
|
||||||
|
const existingWidget = await widgetModel(organization).findOne({
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
widgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingWidget) {
|
||||||
|
const updateWidget = await widgetModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
widgetID: widget.id,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
widgetID: widget.id,
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements,
|
||||||
|
duration: widget?.Data?.duration,
|
||||||
|
},
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ upsert: true, new: true }
|
||||||
|
);
|
||||||
|
if (!updateWidget) {
|
||||||
|
return { status: "Widget update unsuccessfull" };
|
||||||
|
}
|
||||||
|
return { status: "Widget update successfully", data: updateWidget };
|
||||||
|
}
|
||||||
|
const newWidget = await widgetModel(organization).create({
|
||||||
|
widgetID: widget.id,
|
||||||
|
elementType: widget.type,
|
||||||
|
widgetName: widget.title,
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
widgetside: widget.panel,
|
||||||
|
zoneId: zoneId,
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data?.measurements || {},
|
||||||
|
duration: widget?.Data?.duration || "1hr",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (newWidget) {
|
||||||
|
existingPanel.widgets.push(newWidget._id);
|
||||||
|
await existingPanel.save();
|
||||||
|
const widgetData = {
|
||||||
|
type: newWidget.elementType,
|
||||||
|
id: newWidget.widgetID,
|
||||||
|
panel: newWidget.widgetside,
|
||||||
|
title: newWidget.widgetName,
|
||||||
|
};
|
||||||
|
const finaldata = {
|
||||||
|
widgetData: widgetData,
|
||||||
|
zoneId: existingZone.zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: finaldata,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Type mismatch",
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widgetID, userId, zoneId, projectId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const findWidget = await widgetModel(organization).findOne({
|
||||||
|
widgetID: widgetID,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!findWidget) return { status: "Widget not found" };
|
||||||
|
|
||||||
|
const widgetData = await widgetModel(organization).updateOne(
|
||||||
|
{ _id: findWidget._id, isArchive: false, zoneId: zoneId },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (widgetData) {
|
||||||
|
await widgetModel(organization).find({
|
||||||
|
panelID: findWidget.panelID,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const panelData = await panelModel(organization).findOne({
|
||||||
|
_id: findWidget.panelID,
|
||||||
|
isArchive: false,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (panelData.widgets.includes(findWidget._id)) {
|
||||||
|
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||||
|
panelData.widgets.splice(index1, 1);
|
||||||
|
}
|
||||||
|
await panelData.save();
|
||||||
|
|
||||||
|
const activeWidgets = await widgetModel(organization).find({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedWidgets = activeWidgets.map((widget) => ({
|
||||||
|
id: widget.widgetID,
|
||||||
|
type: widget.elementType,
|
||||||
|
title: widget.widgetName,
|
||||||
|
panel: widget.widgetside,
|
||||||
|
data: {
|
||||||
|
duration: "1h",
|
||||||
|
measurements: {},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
const widgetData1 = {
|
||||||
|
widgetDeleteDatas: formattedWidgets,
|
||||||
|
zoneId: zoneId,
|
||||||
|
zoneName: existingZone.zoneName,
|
||||||
|
};
|
||||||
|
return { status: "Success", data: widgetData1 };
|
||||||
|
}
|
||||||
|
return { status: "Widget not found" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widgetID, userId, projectId, zoneId, values } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const findWidget = await widgetModel(organization).findOne({
|
||||||
|
widgetID: widgetID,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!findWidget) return { status: "Data not found" };
|
||||||
|
const updateData = {
|
||||||
|
widgetName: values.widgetName,
|
||||||
|
widgetSide: values.widgetSide,
|
||||||
|
elementType: values.type,
|
||||||
|
Data: {
|
||||||
|
measurement: values.Data.measurement,
|
||||||
|
duration: values.Data.duration,
|
||||||
|
},
|
||||||
|
elementColor: values.color,
|
||||||
|
fontFamily: values.fontFamily,
|
||||||
|
fontStyle: values.fontStyle,
|
||||||
|
fontWeight: values.fontWeight,
|
||||||
|
isArchive: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
await widgetModel(organization).findOneAndUpdate(
|
||||||
|
{ widgetID: widgetID, isArchive: false },
|
||||||
|
updateData,
|
||||||
|
{
|
||||||
|
new: true,
|
||||||
|
upsert: true,
|
||||||
|
setDefaultsOnInsert: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, widgetID, userId, projectId, zoneId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||||
|
|
||||||
|
const existingWidget = await widgetModel(organization)
|
||||||
|
.findOne({
|
||||||
|
widgetID: widgetID,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("Data widgetName -_id");
|
||||||
|
if (!existingWidget) return { status: "Widget not found for the widgetID" };
|
||||||
|
const Datastructure = {
|
||||||
|
measurements: existingWidget.Data.measurements || {},
|
||||||
|
duration: existingWidget.Data.duration || "1h",
|
||||||
|
};
|
||||||
|
const widgetName = existingWidget.widgetName || "Widget";
|
||||||
|
const Data = { Datastructure, widgetName };
|
||||||
|
return { status: "Success", data: Data };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { deleteAssetModel, replaceEventDatas, setAssetModel } from "../../../shared/services/builder/assetService.ts";
|
||||||
|
export const setAssetHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"modelUuid",
|
||||||
|
"modelName",
|
||||||
|
"position",
|
||||||
|
"rotation",
|
||||||
|
"eventData",
|
||||||
|
"modelfileID",
|
||||||
|
"isLocked",
|
||||||
|
"isVisible",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await setAssetModel(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Model created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Updated successfully": { message: "Updated successfully" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Asset_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Asset_Datas ? { data: Asset_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const deleteAssetHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.delete_v1AssetModel || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"modelUuid",
|
||||||
|
"modelName",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteAssetModel(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Model deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"model not found": { message: "model not found" },
|
||||||
|
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Asset_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Asset_Datas ? { data: Asset_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const replaceEventDatasHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.asset_v1EventData || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"modelUuid",
|
||||||
|
"eventData",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await replaceEventDatas(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Data updated successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Model not for this UUID": { message: "Model not for this UUID" },
|
||||||
|
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Asset_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Asset_Datas ? { data: Asset_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { SetCamera } from "../../../shared/services/builder/cameraService.ts";
|
||||||
|
export const SetCameraHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setCamera_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"position",
|
||||||
|
"target",
|
||||||
|
"rotation",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SetCamera(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Camera created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Update Success": { message: "Update Success" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { SetCamera } from "../../../shared/services/builder/cameraService.ts";
|
||||||
|
import { setEnvironment } from "../../../shared/services/builder/EnvironmentService.ts";
|
||||||
|
export const setEnvironmentHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setenvironment_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"roofVisibility", "wallVisibility", "shadowVisibility",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await setEnvironment(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "evironment created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
'evironments updated': { message: 'evironments updated' },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,341 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { CreateLineItems, DeleteLayer, DeleteLineItems, DeleteLinePoints, UpdateLineItems } from "../../../shared/services/builder/lineService.ts";
|
||||||
|
export const CreateLineHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.createLine_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"line",
|
||||||
|
"type",
|
||||||
|
"layer",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await CreateLineItems(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "line created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Update Success": { message: "Update Success" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Line_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const UpdateLineHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.updateLine_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"uuid",
|
||||||
|
"position",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await UpdateLineItems(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "line updated successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Line_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DeleteLineHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"uuid",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLineItems(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "line deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"line not found": { message: "line not found" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Line_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DeleteLayerHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteLineLayer_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"layer",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLayer(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "layer deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"layer not found": { message: "layer not found" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Line_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DeleteLinePointsHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deletePoint_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"uuid",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLinePoints(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "layer deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Line not found": { message: "Line not found" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Line_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { deleteWallItems, setWallItems } from "../../../shared/services/builder/wallService.ts";
|
||||||
|
|
||||||
|
export const setWallItemsHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"modelUuid",
|
||||||
|
"modelName",
|
||||||
|
"position",
|
||||||
|
"type",
|
||||||
|
"csgposition",
|
||||||
|
"csgscale",
|
||||||
|
"quaternion",
|
||||||
|
"scale",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await setWallItems(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "wall Item created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Updated successfully": { message: "Updated successfully" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const deleteWallItemsHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setWallItems_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"modelUuid",
|
||||||
|
"modelName",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteWallItems(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "wall Item deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"model not found": { message: "model not found" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { DelZone, SetZone } from "../../../shared/services/builder/zoneService.ts";
|
||||||
|
|
||||||
|
|
||||||
|
export const SetZoneHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setZone_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"zoneData",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SetZone(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "zone created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"zone updated": { message: "zone updated" },
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DeleteZoneHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteZone_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = [
|
||||||
|
"zoneId",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelZone(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "zone deleted created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { Add3DWidget, Delete3Dwidget, Update3Dwidget } from "../../../shared/services/visualization/widget3dService.ts";
|
||||||
|
export const add3DwidgetHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.addWidget3D || !data?.organization) return;
|
||||||
|
const requiredFields = ["projectId", "userId", "organization", "zoneId", "widget"];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addWidget3DResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Add3DWidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Widget created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||||
|
"3dwidget update successfully": { message: "widget update successfully" },
|
||||||
|
"3dWidget not updated": { message: "3dWidget not updated" },
|
||||||
|
"Widget 3d not created": { message: "Widget 3d not created" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widgemodel3D_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widgemodel3D_Datas ? { data: widgemodel3D_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addWidget3DResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const update3DHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.updateWidget3DPosition || !data?.organization) return;
|
||||||
|
const requiredFields = ["projectId", "id", "position", "rotation", "userId", "organization", "zoneId", "widget"];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateWidget3DPositionResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Update3Dwidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "widget update successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"Widget not updated": { message: "Widget not updated" },
|
||||||
|
"widget not found": { message: "widget not found" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widget3D_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// const updateDatas = {
|
||||||
|
// widget: {
|
||||||
|
// id: update3dwidget.widgetID,
|
||||||
|
// type: update3dwidget.type,
|
||||||
|
// position: update3dwidget.position,
|
||||||
|
// rotation: update3dwidget.rotation,
|
||||||
|
// },
|
||||||
|
// zoneId: zoneId,
|
||||||
|
// };
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widget3D_Datas ? { data: widget3D_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateWidget3DPositionResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const Delete3DwidgetHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteWidget3D || !data?.organization) return;
|
||||||
|
const requiredFields = ["projectId", "id", "userId", "organization", "zoneId",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletewidget3DResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Delete3Dwidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "3DWidget delete unsuccessfull" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"3D widget not found for the ID": { message: "3D widget not found for the ID" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widget3D_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// const delete_Datas = {
|
||||||
|
// zoneId: zoneId,
|
||||||
|
// id: existing3Dwidget.widgetID,
|
||||||
|
// };
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widget3D_Datas ? { data: widget3D_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletewidget3DResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { AddFloat, DelFloat, DuplicateFloat } from "../../../shared/services/visualization/floatWidgetService.ts";
|
||||||
|
export const AddFloatHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.addFloat_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "index", "widget", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.float_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddFloat(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "FloatWidget created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||||
|
"Widget updated successfully": { message: "Widget updated successfully" },
|
||||||
|
"Failed to create FloatWidget": { message: "Failed to create FloatWidget" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const fload_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.float_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DeleteFloatHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteFloat_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "floatWidgetID", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.float_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelFloat(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "FloatingWidget deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||||
|
"FloatWidget not found for the Id": { message: "FloatWidget not found for the Id" },
|
||||||
|
"FloatWidget not deleted": { message: "FloatWidget not deleted" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const fload_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.float_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DuplicateFloatHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.duplicatefloat_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "index", "widget", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.duplicatefloat_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DuplicateFloat(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "duplicate FloatWidget created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||||
|
"FloatWidget update unsuccessfull": { message: "FloatWidget update unsuccessfull" },
|
||||||
|
"FloatWidget not deleted": { message: "FloatWidget not deleted" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const fload_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.duplicatefloat_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { AddPanel, ClearPanel, DelPanel, LockedPanel } from "../../../shared/services/visualization/panelService.ts";
|
||||||
|
export const AddPanelHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.addPanel_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "panelOrder", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addPanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddPanel(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Panels created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"No new panels were created. All panels already exist": { message: "No new panels were created. All panels already exist" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addPanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const DeletePanelHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deletePanel_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "panelName", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelPanel(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Panel deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"Panel Already Deleted": { message: "Panel Already Deleted" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const ClearPanelHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.clearPanel_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "panelName", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.clearPanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await ClearPanel(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "PanelWidgets cleared successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"Requested Panel not found": { message: "Requested Panel not found" },
|
||||||
|
"No widgets to clear": { message: "No widgets to clear" },
|
||||||
|
"Failed to clear widgets in panel": { message: "Failed to clear widgets in panel" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.clearPanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const LockedPanelHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.lockedPanel_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "lockedPanel", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.lockedPanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await LockedPanel(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "PanelWidgets cleared successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"locked panel not updated": { message: "locked panel not updated" },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.lockedPanel_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { AddTemplate, AddTemplateToZone, TemplateDelete } from "../../../shared/services/visualization/templateService.ts";
|
||||||
|
export const AddTemplateHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.addTemplate_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["template", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.template_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddTemplate(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Panels created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"TemplateID alreay exists": { message: "TemplateID alreay exists" },
|
||||||
|
"Template not saved": { message: "Template not saved" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.template_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const addTemplateZoneHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.addTemplateZone_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["template", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addTemplateZone_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddTemplateToZone(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Template placed in Zone" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found ": { message: "Zone not found " },
|
||||||
|
"TemplateID not found": { message: "TemplateID not found" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// const templateZoneDatas = {
|
||||||
|
// template: {
|
||||||
|
// id: existingTemplate.templateID,
|
||||||
|
// name: existingTemplate.templateName,
|
||||||
|
// panelOrder: existingTemplate.panelOrder,
|
||||||
|
// widgets: existingTemplate.widgets,
|
||||||
|
// snapshot: existingTemplate.snapshot,
|
||||||
|
// floatingWidget: existingTemplate.floatWidgets,
|
||||||
|
// },
|
||||||
|
// zoneId: existingZone.zoneId,
|
||||||
|
// zoneName: existingZone.zoneName,
|
||||||
|
// };
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addTemplateZone_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const TemplateDeleteHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteTemplate_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["templateID", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.TemplateDelete_v1Response, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await TemplateDelete(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Template deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Template not Deleted": { message: "Template not Deleted" },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Panel_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(Panel_Datas ? { data: Panel_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.TemplateDelete_v1Response, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import { AddWidget, WidgetDelete } from "../../../shared/services/visualization/widgetService.ts";
|
||||||
|
export const AddWidgetHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.addWidget_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "widget", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.widget_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddWidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Widget created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||||
|
"panelName not found": { message: "panelName not found" },
|
||||||
|
"Widget update unsuccessfull": { message: "Widget update unsuccessfull" },
|
||||||
|
"Type mismatch": { message: "Type mismatch" },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widget_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widget_Datas ? { data: widget_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.widget_v1UpdateResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
|
export const WidgetDeleteHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteWidget_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["zoneId", "widgetID", "projectId", "userId", "organization",];
|
||||||
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
|
status: "MissingFields",
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data?.organization ?? "unknown",
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.widget_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await WidgetDelete(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Widget deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||||
|
"Widget not found": { message: "Widget not found" },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widget_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widget_Datas ? { data: widget_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.widget_v1DeleteResponse, response, connectedUsersByOrg)
|
||||||
|
}
|
||||||
@@ -3,8 +3,20 @@ import jwt from 'jsonwebtoken';
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import AuthModel from '../../shared/V1Models/Auth/userAuthModel.ts';
|
import AuthModel from '../../shared/V1Models/Auth/userAuthModel.ts';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
import { projectDeleteHandleEvent, projectHandleEvent, projecUpdateHandleEvent } from '../controllers/project/projectController.ts';
|
|
||||||
import { addCommentHandleEvent, createThreadHandleEvent, deleteCommentHandleEvent, deleteThreadHandleEvent } from '../controllers/thread/threadController.ts';
|
import { addCommentHandleEvent, createThreadHandleEvent, deleteCommentHandleEvent, deleteThreadHandleEvent } from '../controllers/thread/threadController.ts';
|
||||||
|
import { projectDeleteHandleEvent, projectHandleEvent, projecUpdateHandleEvent } from '../controllers/projectController/projectController.ts';
|
||||||
|
import { setAssetHandleEvent, deleteAssetHandleEvent, replaceEventDatasHandleEvent } from '../controllers/builderController/asset-Controller.ts';
|
||||||
|
import { SetCameraHandleEvent } from '../controllers/builderController/camera-Controller.ts';
|
||||||
|
import { setEnvironmentHandleEvent } from '../controllers/builderController/environment-Controller.ts';
|
||||||
|
import { CreateLineHandleEvent, UpdateLineHandleEvent, DeleteLineHandleEvent, DeleteLayerHandleEvent, DeleteLinePointsHandleEvent } from '../controllers/builderController/line-Controller.ts';
|
||||||
|
import { deleteWallItemsHandleEvent, setWallItemsHandleEvent } from '../controllers/builderController/wall-Controller.ts';
|
||||||
|
import { DeleteZoneHandleEvent, SetZoneHandleEvent } from '../controllers/builderController/zone-Controller.ts';
|
||||||
|
import { add3DwidgetHandleEvent, Delete3DwidgetHandleEvent, update3DHandleEvent } from '../controllers/vizualizationController/3dWidget-Controller.ts';
|
||||||
|
import { AddFloatHandleEvent, DeleteFloatHandleEvent, DuplicateFloatHandleEvent } from '../controllers/vizualizationController/floatWidget-Controller.ts';
|
||||||
|
import { AddPanelHandleEvent, ClearPanelHandleEvent, DeletePanelHandleEvent, LockedPanelHandleEvent } from '../controllers/vizualizationController/panel-Controller.ts';
|
||||||
|
import { AddTemplateHandleEvent, addTemplateZoneHandleEvent, TemplateDeleteHandleEvent } from '../controllers/vizualizationController/template-Controller.ts';
|
||||||
|
import { AddWidgetHandleEvent, WidgetDeleteHandleEvent } from '../controllers/vizualizationController/widget-Controller.ts';
|
||||||
|
|
||||||
export const SocketServer = (httpServer: any) => {
|
export const SocketServer = (httpServer: any) => {
|
||||||
const io = new Server(httpServer, {
|
const io = new Server(httpServer, {
|
||||||
cors: {
|
cors: {
|
||||||
@@ -13,11 +25,15 @@ export const SocketServer = (httpServer: any) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const namespaces = {
|
const namespaces = {
|
||||||
project: io.of('/project'),
|
project: io.of('/project'),
|
||||||
thread: io.of('/thread'),
|
thread: io.of('/thread'),
|
||||||
|
Builder: io.of("/Builder"),
|
||||||
|
visualization: io.of("/Visualization"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// const onlineUsers = new Map<string, Set<string>>();
|
// const onlineUsers = new Map<string, Set<string>>();
|
||||||
const onlineUsers: { [organization: string]: Set<string> } = {};
|
const onlineUsers: { [organization: string]: Set<string> } = {};
|
||||||
|
|
||||||
@@ -70,7 +86,15 @@ export const SocketServer = (httpServer: any) => {
|
|||||||
const user = (socket as any).user;
|
const user = (socket as any).user;
|
||||||
const organization = user.organization;
|
const organization = user.organization;
|
||||||
const email = user.email;
|
const email = user.email;
|
||||||
console.log(`🔍 Received organization: ${organization}`);
|
|
||||||
|
// namespace.on("connection", (socket: Socket) => {
|
||||||
|
// console.log(`✅ Client connected to ${namespace.name}: ${socket.id}`);
|
||||||
|
// // Extract organization from query parameters
|
||||||
|
|
||||||
|
// const organization = socket.handshake.query.organization as string;
|
||||||
|
// const email = socket.handshake.query.email as string;
|
||||||
|
// // const {organization,email} = socket.handshake.auth
|
||||||
|
// console.log(`🔍 Received organization: ${organization}`);
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
socket.join(organization);
|
socket.join(organization);
|
||||||
@@ -115,5 +139,43 @@ export const SocketServer = (httpServer: any) => {
|
|||||||
|
|
||||||
handleNamespace(namespaces.project,projectHandleEvent,projectDeleteHandleEvent,projecUpdateHandleEvent)
|
handleNamespace(namespaces.project,projectHandleEvent,projectDeleteHandleEvent,projecUpdateHandleEvent)
|
||||||
handleNamespace(namespaces.thread,createThreadHandleEvent,deleteThreadHandleEvent,addCommentHandleEvent,deleteCommentHandleEvent)
|
handleNamespace(namespaces.thread,createThreadHandleEvent,deleteThreadHandleEvent,addCommentHandleEvent,deleteCommentHandleEvent)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
handleNamespace(namespaces.project, projectHandleEvent, projectDeleteHandleEvent, projecUpdateHandleEvent)
|
||||||
|
handleNamespace(namespaces.Builder,
|
||||||
|
setAssetHandleEvent,
|
||||||
|
deleteAssetHandleEvent,
|
||||||
|
replaceEventDatasHandleEvent,
|
||||||
|
SetCameraHandleEvent,
|
||||||
|
setEnvironmentHandleEvent,
|
||||||
|
CreateLineHandleEvent,
|
||||||
|
UpdateLineHandleEvent,
|
||||||
|
DeleteLineHandleEvent,
|
||||||
|
DeleteLayerHandleEvent,
|
||||||
|
DeleteLinePointsHandleEvent,
|
||||||
|
setWallItemsHandleEvent,
|
||||||
|
deleteWallItemsHandleEvent,
|
||||||
|
SetZoneHandleEvent,
|
||||||
|
DeleteZoneHandleEvent
|
||||||
|
)
|
||||||
|
handleNamespace(namespaces.visualization,
|
||||||
|
add3DwidgetHandleEvent,
|
||||||
|
update3DHandleEvent,
|
||||||
|
Delete3DwidgetHandleEvent,
|
||||||
|
AddFloatHandleEvent,
|
||||||
|
DeleteFloatHandleEvent,
|
||||||
|
DuplicateFloatHandleEvent,
|
||||||
|
AddPanelHandleEvent,
|
||||||
|
DeletePanelHandleEvent,
|
||||||
|
ClearPanelHandleEvent,
|
||||||
|
LockedPanelHandleEvent,
|
||||||
|
AddTemplateHandleEvent,
|
||||||
|
addTemplateZoneHandleEvent,
|
||||||
|
TemplateDeleteHandleEvent,
|
||||||
|
AddWidgetHandleEvent,
|
||||||
|
WidgetDeleteHandleEvent
|
||||||
|
)
|
||||||
return io;
|
return io;
|
||||||
};
|
};
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||||
export const addWidget = async (data: any,callback:any) => {
|
export const addWidget = async (data: any, callback: any) => {
|
||||||
const { organization, panel, zoneId, widget } = data;
|
const { organization, panel, zoneId, widget } = data;
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -59,7 +59,7 @@ export const addWidget = async (data: any,callback:any) => {
|
|||||||
callback({
|
callback({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Widget update unsuccessfull",
|
message: "Widget update unsuccessfull",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -106,7 +106,7 @@ export const addWidget = async (data: any,callback:any) => {
|
|||||||
callback({
|
callback({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Widget created successfully",
|
message: "Widget created successfully",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -114,7 +114,6 @@ export const addWidget = async (data: any,callback:any) => {
|
|||||||
data: finaldata,
|
data: finaldata,
|
||||||
organization: organization,
|
organization: organization,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -126,7 +125,7 @@ export const addWidget = async (data: any,callback:any) => {
|
|||||||
callback({
|
callback({
|
||||||
success: false,
|
success: false,
|
||||||
message: "widge not found",
|
message: "widge not found",
|
||||||
})
|
});
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "widge not found",
|
message: "widge not found",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
export const EVENTS = {
|
export const EVENTS = {
|
||||||
connection: "connection",
|
connection: "connection",
|
||||||
disconnect:"disconnect",
|
disconnect: "disconnect",
|
||||||
//userActiveStatus
|
//userActiveStatus
|
||||||
userConnect:"userConnectResponse",
|
userConnect: "userConnectResponse",
|
||||||
userDisConnect:"userDisConnectResponse",
|
userDisConnect: "userDisConnectResponse",
|
||||||
// Room management events
|
// Room management events
|
||||||
joinRoom: 'joinRoom',
|
joinRoom: 'joinRoom',
|
||||||
createroom: "createRoom", // When a client joins a room
|
createroom: "createRoom", // When a client joins a room
|
||||||
@@ -32,62 +32,62 @@ export const EVENTS = {
|
|||||||
wallItemsDeleteResponse: "wallItemsDeleteResponse",
|
wallItemsDeleteResponse: "wallItemsDeleteResponse",
|
||||||
wallItemError: "wallItemError",
|
wallItemError: "wallItemError",
|
||||||
//Lines
|
//Lines
|
||||||
createLine:"v1:Line:create",
|
createLine: "v1:Line:create",
|
||||||
createLineResponse:"Line:response:create",
|
createLineResponse: "Line:response:create",
|
||||||
updateLine:"v1:Line:update",
|
updateLine: "v1:Line:update",
|
||||||
updateLineResponse:"Line:response:update",
|
updateLineResponse: "Line:response:update",
|
||||||
deleteLine:"v1:Line:delete",
|
deleteLine: "v1:Line:delete",
|
||||||
deleteLineResponse:"Line:response:delete",
|
deleteLineResponse: "Line:response:delete",
|
||||||
deletePoint:"v1:Line:delete:point",
|
deletePoint: "v1:Line:delete:point",
|
||||||
deletePointResponse:"Line:response:delete:point",
|
deletePointResponse: "Line:response:delete:point",
|
||||||
deleteLineLayer:"v1:Line:delete:layer",
|
deleteLineLayer: "v1:Line:delete:layer",
|
||||||
deleteLineLayerResponse:"Line:response:delete:layer",
|
deleteLineLayerResponse: "Line:response:delete:layer",
|
||||||
//zone
|
//zone
|
||||||
setZone:"v2:zone:set",
|
setZone: "v2:zone:set",
|
||||||
zoneUpdateResponse:"zone:response:updates",
|
zoneUpdateResponse: "zone:response:updates",
|
||||||
deleteZone:"v2:zone:delete",
|
deleteZone: "v2:zone:delete",
|
||||||
ZoneDeleteResponse:"zone:response:delete",
|
ZoneDeleteResponse: "zone:response:delete",
|
||||||
|
|
||||||
//visualization
|
//visualization
|
||||||
//panel
|
//panel
|
||||||
addPanel:"v2:viz-panel:add",
|
addPanel: "v2:viz-panel:add",
|
||||||
panelUpdateResponse:"viz-panel:response:updates",
|
panelUpdateResponse: "viz-panel:response:updates",
|
||||||
deletePanel:"v2:viz-panel:delete",
|
deletePanel: "v2:viz-panel:delete",
|
||||||
PanelDeleteResponse:"viz-panel:response:delete",
|
PanelDeleteResponse: "viz-panel:response:delete",
|
||||||
clearPanel:"v2:viz-panel:clear",
|
clearPanel: "v2:viz-panel:clear",
|
||||||
PanelClearResponse:"viz-panel:response:clear",
|
PanelClearResponse: "viz-panel:response:clear",
|
||||||
lockedPanel:"v2:viz-panel:locked",
|
lockedPanel: "v2:viz-panel:locked",
|
||||||
PanelLockedResponse:"viz-panel:response:locked",
|
PanelLockedResponse: "viz-panel:response:locked",
|
||||||
|
|
||||||
//widget
|
//widget
|
||||||
addWidget:"v2:viz-widget:add",
|
addWidget: "v2:viz-widget:add",
|
||||||
widgetUpdateResponse:"viz-widget:response:updates",
|
widgetUpdateResponse: "viz-widget:response:updates",
|
||||||
deleteWidget:"v2:viz-widget:delete",
|
deleteWidget: "v2:viz-widget:delete",
|
||||||
widgetDeleteResponse:"viz-widget:response:delete",
|
widgetDeleteResponse: "viz-widget:response:delete",
|
||||||
|
|
||||||
//float
|
//float
|
||||||
addFloat: "v2:viz-float:add",
|
addFloat: "v2:viz-float:add",
|
||||||
floatUpdateResponse: "viz-float:response:updates",
|
floatUpdateResponse: "viz-float:response:updates",
|
||||||
deleteFloat: "v2:viz-float:delete",
|
deleteFloat: "v2:viz-float:delete",
|
||||||
floatDeleteResponse: "viz-float:response:delete",
|
floatDeleteResponse: "viz-float:response:delete",
|
||||||
duplicatefloat:"v2:viz-float:addDuplicate",
|
duplicatefloat: "v2:viz-float:addDuplicate",
|
||||||
duplicatefloatUpdateResponse:"viz-float:response:addDuplicate",
|
duplicatefloatUpdateResponse: "viz-float:response:addDuplicate",
|
||||||
|
|
||||||
//template
|
//template
|
||||||
addTemplate:"v2:viz-template:add",
|
addTemplate: "v2:viz-template:add",
|
||||||
templateUpdateResponse:"viz-template:response:add",
|
templateUpdateResponse: "viz-template:response:add",
|
||||||
addTemplateZone:"v2:viz-template:addToZone",
|
addTemplateZone: "v2:viz-template:addToZone",
|
||||||
addTemplateZoneResponse:"viz-template:response:addTemplateZone",
|
addTemplateZoneResponse: "viz-template:response:addTemplateZone",
|
||||||
deleteTemplate:"v2:viz-template:deleteTemplate",
|
deleteTemplate: "v2:viz-template:deleteTemplate",
|
||||||
TemplateDeleteResponse:"viz-template:response:delete",
|
TemplateDeleteResponse: "viz-template:response:delete",
|
||||||
|
|
||||||
|
|
||||||
//model-asset
|
//model-asset
|
||||||
setAssetModel: "v2:model-asset:add",
|
setAssetModel: "v2:model-asset:add",
|
||||||
assetUpdateResponse: "model-asset:response:updates",
|
assetUpdateResponse: "model-asset:response:updates",
|
||||||
deleteAssetModel:"v2:model-asset:delete",
|
deleteAssetModel: "v2:model-asset:delete",
|
||||||
assetDeleteResponse: "model-asset:response:updates",
|
assetDeleteResponse: "model-asset:response:updates",
|
||||||
assetEventData:"v2:model-asset:updateEventData",
|
assetEventData: "v2:model-asset:updateEventData",
|
||||||
assetEventDataResponse: "model-asset:response:updateEventData",
|
assetEventDataResponse: "model-asset:response:updateEventData",
|
||||||
|
|
||||||
|
|
||||||
@@ -117,4 +117,78 @@ addComment:"v1-Comment:response:add",
|
|||||||
addCommentResponse:"v1-Comment:response:add",
|
addCommentResponse:"v1-Comment:response:add",
|
||||||
deleteComment:"v1-Comment:response:delete",
|
deleteComment:"v1-Comment:response:delete",
|
||||||
deleteCommentResponse:"v1-Comment:response:delete",
|
deleteCommentResponse:"v1-Comment:response:delete",
|
||||||
|
//3Dwidget
|
||||||
|
addWidget3D: "v1:viz-3D-widget:add",
|
||||||
|
addWidget3DResponse: "v1:viz-widget3D:response:add",
|
||||||
|
updateWidget3DPosition: "v1:viz-3D-widget:modifyPositionRotation",
|
||||||
|
updateWidget3DPositionResponse: "v1:viz-widget3D:response:modifyPositionRotation",
|
||||||
|
deleteWidget3D: "v1:viz-3D-widget:delete",
|
||||||
|
deletewidget3DResponse: "v1:viz-widget3D:response:delete",
|
||||||
|
|
||||||
|
//panel
|
||||||
|
addPanel_v1: "v1:viz-panel:add",
|
||||||
|
addPanel_v1Response: "v1:viz-panel:response:add",
|
||||||
|
deletePanel_v1: "v1:viz-panel:delete",
|
||||||
|
deletePanel_v1Response: "v1:viz-panel:response:delete",
|
||||||
|
clearPanel_v1: "v1:viz-panel:clear",
|
||||||
|
clearPanel_v1Response: "v1:viz-panel:response:clear",
|
||||||
|
lockedPanel_v1: "v1:viz-panel:locked",
|
||||||
|
lockedPanel_v1Response: "v1:viz-panel:response:locked",
|
||||||
|
//float
|
||||||
|
addFloat_v1: "v1:viz-float:add",
|
||||||
|
float_v1UpdateResponse: "v1:viz-float:response:updates",
|
||||||
|
deleteFloat_v1: "v1:viz-float:delete",
|
||||||
|
float_v1DeleteResponse: "v1:viz-float:response:delete",
|
||||||
|
duplicatefloat_v1: "v1:viz-float:addDuplicate",
|
||||||
|
duplicatefloat_v1UpdateResponse: "v1:viz-float:response:addDuplicate",
|
||||||
|
|
||||||
|
//template
|
||||||
|
addTemplate_v1: "v1:viz-template:add",
|
||||||
|
template_v1UpdateResponse: "v1:viz-template:response:add",
|
||||||
|
addTemplateZone_v1: "v1:viz-template:addToZone",
|
||||||
|
addTemplateZone_v1Response: "v1:viz-template:response:addTemplateZone",
|
||||||
|
deleteTemplate_v1: "v1:viz-template:deleteTemplate",
|
||||||
|
TemplateDelete_v1Response: "v1:viz-template:response:delete",
|
||||||
|
|
||||||
|
//widget
|
||||||
|
addWidget_v1: "v1:viz-widget:add",
|
||||||
|
widget_v1UpdateResponse: "v1:viz-widget:response:updates",
|
||||||
|
deleteWidget_v1: "v1:viz-widget:delete",
|
||||||
|
widget_v1DeleteResponse: "v1:viz-widget:response:delete",
|
||||||
|
//model-asset
|
||||||
|
setAssetModel_v1: "v1:model-asset:add",
|
||||||
|
asset_v1UpdateResponse: "v1:model-asset:response:updates",
|
||||||
|
delete_v1AssetModel: "v1:model-asset:delete",
|
||||||
|
asset_v1DeleteResponse: "v1:model-asset:response:updates",
|
||||||
|
asset_v1EventData: "v1:model-asset:updateEventData",
|
||||||
|
asset_v1EventDataResponse: "v1:model-asset:response:updateEventData",
|
||||||
|
// Camera
|
||||||
|
setCamera_v1: 'v1:Camera:set',
|
||||||
|
camera_v1CreateResponse: "v1:camera:Response:update",
|
||||||
|
//Lines
|
||||||
|
createLine_v1: "v1:Line:create",
|
||||||
|
createLine_v1Response: "v1:Line:response:create",
|
||||||
|
updateLine_v1: "v1:Line:update",
|
||||||
|
updateLine_v1Response: "v1:Line:response:update",
|
||||||
|
deleteLine_v1: "v1:Line:delete",
|
||||||
|
deleteLine_v1Response: "v1:Line:response:delete",
|
||||||
|
deletePoint_v1: "v1:Line:delete:point",
|
||||||
|
deletePoint_v1Response: "v1:Line:response:delete:point",
|
||||||
|
deleteLineLayer_v1: "v1:Line:delete:layer",
|
||||||
|
deleteLineLayer_v1Response: "v1:Line:response:delete:layer",
|
||||||
|
//Environment
|
||||||
|
setenvironment_v1: "v1:Environment:set",
|
||||||
|
Environment_v1UpdateResponse: "v1:EnvironmentUpdateResponse",
|
||||||
|
|
||||||
|
//WALLItems
|
||||||
|
setWallItems_v1: "v1:wallItems:set",
|
||||||
|
wallItems_v1UpdateResponse: "v1:wallItemsUpdateResponse",
|
||||||
|
deleteWallItems_v1: "v1:wallItems:delete",
|
||||||
|
wallItems_v1DeleteResponse: "v1:wallItemsDeleteResponse",
|
||||||
|
//zone
|
||||||
|
setZone_v1: "v1:zone:set",
|
||||||
|
zone_v1UpdateResponse: "v1:zone:response:updates",
|
||||||
|
deleteZone_v1: "v1:zone:delete",
|
||||||
|
Zone_v1DeleteResponse: "v1:zone:response:delete",
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ import {
|
|||||||
projectDeleteHandleEvent,
|
projectDeleteHandleEvent,
|
||||||
projectHandleEvent,
|
projectHandleEvent,
|
||||||
projecUpdateHandleEvent,
|
projecUpdateHandleEvent,
|
||||||
} from "../controllers/project/projectController.ts";
|
} from "../controllers/projectController/projectController.ts";
|
||||||
import { getUserRole } from "../utils/getUsers.ts";
|
import { getUserRole } from "../utils/getUsers.ts";
|
||||||
|
|
||||||
const cameraHandleEvent = async (
|
const cameraHandleEvent = async (
|
||||||
|
|||||||
Reference in New Issue
Block a user