From c38a698692ea227a06bbe4150f4f1474ef855187 Mon Sep 17 00:00:00 2001 From: Nivetharamesh Date: Thu, 29 May 2025 15:34:12 +0530 Subject: [PATCH] Controller and routing for the Vizualtion and builder --- src/api-server/Routes/panelRoutes.ts | 2 +- .../v1EnvironmentController.ts | 131 +++ .../builderController/v1LineController.ts | 277 +++++ .../builderController/v1assetController.ts | 327 ++++++ .../builderController/v1cameraController.ts | 43 +- .../builderController/v1wallController.ts | 46 +- .../builderController/v1zoneController.ts | 259 ++++- .../trashController/v1trashController.ts | 66 ++ .../v1widgetController.ts | 130 +++ .../v1Routes/BuilderRoutes/v1-ZoneRoutes.ts | 56 ++ .../v1Routes/BuilderRoutes/v1-assetRoutes.ts | 37 + .../v1Routes/BuilderRoutes/v1-cameraRoutes.ts | 31 + .../v1Routes/BuilderRoutes/v1-linesRoutes.ts | 51 + .../v1Routes/BuilderRoutes/v1-wallRoutes.ts | 30 + src/api-server/V1/v1Routes/v1-trashRoutes.ts | 8 + .../vizRoutes.ts/v1-FloatWidgetRoutes.ts | 44 + .../vizRoutes.ts/v1-TemplateRoutes.ts | 37 + .../v1Routes/vizRoutes.ts/v1-panelRoutes.ts | 31 + .../vizRoutes.ts/v1-widget3dRoutes.ts | 38 + .../v1Routes/vizRoutes.ts/v1-widgetRoutes.ts | 37 + src/api-server/app.ts | 28 +- .../services/builder/EnvironmentService.ts | 179 ++-- src/shared/services/builder/assetService.ts | 948 ++++++++++-------- src/shared/services/builder/cameraService.ts | 17 +- src/shared/services/builder/lineService.ts | 81 +- src/shared/services/builder/wallService.ts | 9 +- src/shared/services/builder/zoneService.ts | 52 +- .../services/project/project-Services.ts | 1 - src/shared/services/trash/trashService.ts | 34 +- .../visualization/floatWidgetService.ts | 63 +- .../services/visualization/panelService.ts | 63 +- .../services/visualization/templateService.ts | 37 +- .../services/visualization/widget3dService.ts | 59 +- .../services/visualization/widgetService.ts | 197 +++- 34 files changed, 2523 insertions(+), 926 deletions(-) create mode 100644 src/api-server/V1/v1Controllers/builderController/v1EnvironmentController.ts create mode 100644 src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts create mode 100644 src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts create mode 100644 src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts create mode 100644 src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts create mode 100644 src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts diff --git a/src/api-server/Routes/panelRoutes.ts b/src/api-server/Routes/panelRoutes.ts index cc391f1..63ef5ef 100644 --- a/src/api-server/Routes/panelRoutes.ts +++ b/src/api-server/Routes/panelRoutes.ts @@ -1,5 +1,5 @@ import * as express from "express"; -import { PanelService } from "../controller/visualization/PanelService.ts"; +import { PanelService } from "../controller/visualization/panelService.ts"; const router = express.Router(); /** * @swagger diff --git a/src/api-server/V1/v1Controllers/builderController/v1EnvironmentController.ts b/src/api-server/V1/v1Controllers/builderController/v1EnvironmentController.ts new file mode 100644 index 0000000..9100e7a --- /dev/null +++ b/src/api-server/V1/v1Controllers/builderController/v1EnvironmentController.ts @@ -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 => { + 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 => { + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Controllers/builderController/v1LineController.ts b/src/api-server/V1/v1Controllers/builderController/v1LineController.ts index e69de29..9c5308d 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1LineController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1LineController.ts @@ -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 => { + 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 => { + 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 => { + 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 => { + 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 => { + 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 => { + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Controllers/builderController/v1assetController.ts b/src/api-server/V1/v1Controllers/builderController/v1assetController.ts index e69de29..ce110b3 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1assetController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1assetController.ts @@ -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 => { + 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 => { + 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 => { + 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 => { + 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 => { + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts index 0d545cd..96d329c 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts @@ -1,8 +1,9 @@ -import { Request, Response } from "express"; +import { Response } from "express"; import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; import { GetCamers, + onlineActiveDatas, SetCamera, } from "../../../../shared/services/builder/cameraService.ts"; @@ -75,6 +76,7 @@ export const CameraList = async ( ): Promise => { try { const { organization, userId } = req.user || {}; + const { projectId } = req.params; if (!organization || !userId) { res.status(400).json({ message: "All fields are required", @@ -84,6 +86,7 @@ export const CameraList = async ( const result = await GetCamers({ organization, userId, + projectId, }); switch (result.status) { @@ -110,3 +113,41 @@ export const CameraList = async ( }); } }; +export const ActiveOnlineController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Controllers/builderController/v1wallController.ts b/src/api-server/V1/v1Controllers/builderController/v1wallController.ts index 61958c6..33dccbe 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1wallController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1wallController.ts @@ -1,8 +1,7 @@ -import { Request, Response } from "express"; +import { Response } from "express"; import { WallItems } from "../../../../shared/services/builder/wallService.ts"; import { error } from "console"; import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; - export const WallSetup = async ( req: AuthenticatedRequest, res: Response @@ -18,7 +17,6 @@ export const WallSetup = async ( csgscale, quaternion, scale, - // versionId projectId, } = req.body; if ( @@ -29,10 +27,10 @@ export const WallSetup = async ( !projectId || !csgscale || !csgposition || - // !versionId || !quaternion || !scale || - !organization + !organization || + !userId ) { res.status(400).json({ message: "All fields are required!", @@ -42,7 +40,6 @@ export const WallSetup = async ( const result = await WallItems.setWallItems({ projectId, modelUuid, - // versionId, modelName, position, type, @@ -51,13 +48,17 @@ export const WallSetup = async ( quaternion, scale, organization, + userId, }); switch (result.status) { + case "User not found": + res.status(404).json({ message: "User not found" }); + break; case "Updated successfully": res.status(200).json(result.data); break; case "wall Item created successfully": - res.status(200).json(result.data); + res.status(201).json(result.data); break; default: res.status(500).json(error); @@ -75,9 +76,9 @@ export const WallGet = async ( res: Response ): Promise => { try { - const { organization, role, userId } = req.user || {}; + const { organization, userId } = req.user || {}; const { projectId } = req.params; - if (!organization || !role || !userId || !projectId) { + if (!organization || !userId || !projectId) { res.status(400).json({ message: "All fields are required", }); @@ -85,21 +86,21 @@ export const WallGet = async ( } const result = await WallItems.getWallItems({ organization, - role, userId, projectId, }); switch (result.status) { + case "User not found": + res.status(404).json({ message: "User not found" }); + break; case "wallitems not found": res.status(404).json({ message: "wallitems not found", }); break; case "Success": - res.status(200).json({ - WallItems: result.data, - }); + res.status(200).json(result.data); break; default: res.status(500).json({ @@ -118,16 +119,9 @@ export const WallDelete = async ( res: Response ): Promise => { try { - const { organization, role, userId } = req.user || {}; + const { organization, userId } = req.user || {}; const { projectId, modelName, modelUuid } = req.body; - if ( - !organization || - !role || - !userId || - !projectId || - !modelName || - !modelUuid - ) { + if (!organization || !userId || !projectId || !modelName || !modelUuid) { res.status(400).json({ message: "All fields are required", }); @@ -135,7 +129,6 @@ export const WallDelete = async ( } const result = await WallItems.deleteWallItems({ organization, - role, userId, projectId, modelName, @@ -143,15 +136,16 @@ export const WallDelete = async ( }); switch (result.status) { + case "User not found": + res.status(404).json({ message: "User not found" }); + break; case "model not found": res.status(404).json({ message: "model not found", }); break; case "Success": - res.status(200).json({ - message: "WallItem deleted", - }); + res.status(200).json(result.data); break; default: res.status(500).json({ diff --git a/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts b/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts index 272938b..66e451b 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts @@ -1,61 +1,51 @@ -import { Request, Response } from "express"; - +import { Response } from "express"; import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; import { - GetCamers, - SetCamera, -} from "../../../../shared/services/builder/cameraService.ts"; + DelZone, + GetZones, + SetZone, + SingleZonePanelData, + VizZoneDatas, + ZoneData, +} from "../../../../shared/services/builder/zoneService.ts"; -export const SetNewCamera = async ( +export const CreateZoneController = async ( req: AuthenticatedRequest, res: Response ): Promise => { try { - const { organization, role, userId } = req.user || {}; - const { position, target, rotation, projectId, versionId } = req.body; - if ( - !organization || - !role || - !userId || - !position || - !target || - !rotation || - !projectId || - !versionId - ) { + const { organization, userId } = req.user || {}; + const { zoneData, projectId } = req.body; + if (!organization || !userId || !zoneData || !projectId) { res.status(400).json({ message: "All fields are required", }); return; } const data = { - position, - target, - rotation, + zoneData, projectId, - versionId, organization, - role, userId, }; - const result = await SetCamera(data); + const result = await SetZone(data); switch (result.status) { - case "Project not found": - res.status(404).json({ - message: "Project not found", - TrashDatas: [], + case "User not found": + res.status(200).json({ + message: "User not found", }); break; - - case "Update Success": + case "zone updated": res.status(200).json({ - TrashDatas: result.data, + message: "zone updated", + ZoneData: result.data, }); break; case "Success": res.status(200).json({ - TrashDatas: result.data, + message: "zone created", + ZoneData: result.data, }); break; default: @@ -71,29 +61,35 @@ export const SetNewCamera = async ( }); } }; -export const CameraList = async ( +export const DeleteZoneController = async ( req: AuthenticatedRequest, res: Response ): Promise => { try { - const { organization, role, userId } = req.user || {}; - if (!organization || !role || !userId) { + const { organization, userId } = req.user || {}; + const { zoneId, projectId } = req.body; + if (!organization || !userId || !zoneId || !projectId) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await GetCamers({ + const result = await DelZone({ organization, - role, + zoneId, + projectId, userId, }); switch (result.status) { - case "Project not found": + case "User not found": res.status(404).json({ - message: "Project not found", - TrashDatas: [], + message: "User not found", + }); + break; + case "Invalid zone ID": + res.status(404).json({ + message: "Zone not found for the UUID", }); break; case "Success": @@ -113,3 +109,186 @@ export const CameraList = async ( }); } }; +export const GetZoneController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + 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 => { + 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 => { + 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 => { + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Controllers/trashController/v1trashController.ts b/src/api-server/V1/v1Controllers/trashController/v1trashController.ts index 6350ff1..1d7c3f8 100644 --- a/src/api-server/V1/v1Controllers/trashController/v1trashController.ts +++ b/src/api-server/V1/v1Controllers/trashController/v1trashController.ts @@ -20,6 +20,11 @@ export const GetTrashList = async ( const result = await TrashDatas({ organization, role, userId }); switch (result.status) { + case "User not found": + res.status(404).json({ + message: "User not found", + }); + break; case "Trash is Empty": res.status(200).json({ message: "Trash is Empty", @@ -69,6 +74,11 @@ export const RestoreTrash = async ( }); 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", @@ -97,3 +107,59 @@ export const RestoreTrash = async ( }); } }; +export const DeleteTrash = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts index 7112567..bc75b63 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts @@ -2,6 +2,8 @@ import { Response } from "express"; import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; import { AddWidget, + GetWidget, + UpdateWidget, WidgetDelete, } from "../../../../shared/services/visualization/widgetService.ts"; @@ -128,3 +130,131 @@ export const WidgetDeleteController = async ( return; } }; +export const WidgetUpdateController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + 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 => { + 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; + } +}; diff --git a/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts b/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts index e69de29..116c524 100644 --- a/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts +++ b/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts b/src/api-server/V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts index e69de29..67016d3 100644 --- a/src/api-server/V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts +++ b/src/api-server/V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts b/src/api-server/V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts index e69de29..1fe2de4 100644 --- a/src/api-server/V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts +++ b/src/api-server/V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts b/src/api-server/V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts index e69de29..211d9fd 100644 --- a/src/api-server/V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts +++ b/src/api-server/V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts b/src/api-server/V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts index e69de29..dfb9316 100644 --- a/src/api-server/V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts +++ b/src/api-server/V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/v1-trashRoutes.ts b/src/api-server/V1/v1Routes/v1-trashRoutes.ts index 91eff2c..fa6b150 100644 --- a/src/api-server/V1/v1Routes/v1-trashRoutes.ts +++ b/src/api-server/V1/v1Routes/v1-trashRoutes.ts @@ -2,6 +2,7 @@ import express from "express"; import { tokenValidator } from "../../../shared/utils/token.ts"; import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; import { + DeleteTrash, GetTrashList, RestoreTrash, } from "../../V1/v1Controllers/trashController/v1trashController.ts"; @@ -21,4 +22,11 @@ v1TrashRoutes.patch( // authorizedRoles("Admin", "User"), RestoreTrash ); + +v1TrashRoutes.patch( + "/Trash/Delete", + tokenValidator, + // authorizedRoles("Admin", "User"), + DeleteTrash +); export default v1TrashRoutes; diff --git a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts new file mode 100644 index 0000000..1d0d45d --- /dev/null +++ b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts new file mode 100644 index 0000000..5ee9f48 --- /dev/null +++ b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts new file mode 100644 index 0000000..999fe03 --- /dev/null +++ b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts new file mode 100644 index 0000000..103d429 --- /dev/null +++ b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts @@ -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; diff --git a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts new file mode 100644 index 0000000..dd997a1 --- /dev/null +++ b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts @@ -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; diff --git a/src/api-server/app.ts b/src/api-server/app.ts index eeaa666..6fb13d0 100644 --- a/src/api-server/app.ts +++ b/src/api-server/app.ts @@ -25,6 +25,16 @@ import Authrouter from "./V1/v1Routes/authRoutes.ts"; import v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts"; import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.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"; redis; const app = express(); @@ -94,9 +104,19 @@ app.use("/api/v1", trashRouter); app.use("/api/v1", homePageRouter); //New versions--based on the token and role based -app.use("/api/v2", Authrouter); -app.use("/api/v2", v1projectRouter); -app.use("/api/v2", v1TrashRoutes); -app.use("/api/v2", v1homeRoutes); +app.use("/api/V1", Authrouter); +app.use("/api/V1", v1projectRouter); +app.use("/api/V1", v1TrashRoutes); +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; diff --git a/src/shared/services/builder/EnvironmentService.ts b/src/shared/services/builder/EnvironmentService.ts index 5f5a87a..af57eaf 100644 --- a/src/shared/services/builder/EnvironmentService.ts +++ b/src/shared/services/builder/EnvironmentService.ts @@ -1,86 +1,119 @@ import environmentModel from "../../V1Models/Environment/environments-Model.ts"; -import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.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; + 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 + data: EnvironmentInput ): Promise<{ status: string; data?: Object }> => { - try { - const { roofVisibility, wallVisibility, 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 }) - if (findvalue) { - const updatevalue = await environmentModel(organization).findOneAndUpdate( - { userId: userId, projectId: projectId }, { roofVisibility: roofVisibility, wallVisibility: wallVisibility, shadowVisibility: shadowVisibility }, { new: true }); - // return { success: true, message: 'evironments updated', data: updatevalue,organization:organization } - return { status: 'evironments updated', data: updatevalue } - } else { - const newValue = await environmentModel(organization).create({ userId, projectId, roofVisibility, wallVisibility, shadowVisibility }); - // return { success: true, message: 'evironments created', data: newValue,organization:organization } - return { status: 'Success', data: newValue } - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } + 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: EnvironmentInput + 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" }; + 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 - }); - if (!findValue) { - // res.status(200).json("user not found"); - return { status: 'evironments user not found' } - } else { - // res.status(201).json(findValue); - return { status: 'Success', data: findValue } - } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } + 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 }; } -}; \ No newline at end of file + } catch (error: unknown) { + if (error instanceof Error) { + return { + status: error.message, + }; + } else { + return { + status: "An unexpected error occurred", + }; + } + } +}; diff --git a/src/shared/services/builder/assetService.ts b/src/shared/services/builder/assetService.ts index 821733e..edf8796 100644 --- a/src/shared/services/builder/assetService.ts +++ b/src/shared/services/builder/assetService.ts @@ -1,473 +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"; +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; + 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 + 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, - }; + 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 { - 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, - }; + assetData.eventData = { + type: typedEventData.type, + point: typedEventData.point, + }; } - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; + } + + 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 { - return { - status: "An unexpected error occurred", - }; + 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: setAssetInput + 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, - // }; - } - 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: "Model deleted successfully", - data: archivedAsset, - }; - - } catch (error: unknown) { - if (error instanceof Error) { - return { - status: error.message, - }; - } else { - return { - status: "An unexpected error occurred", - }; - } + 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: setAssetInput + 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; + 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 (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", - }; - } + // 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: setAssetInput + 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", - }; - } + 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: setAssetInput + 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"); + 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", - }; - } + if (!findValues || findValues.length === 0) { + return { status: "floorItems not found" }; + // return res.status(200).json({ message: "floorItems not found" }); } -}; \ No newline at end of file + + 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", + }; + } + } +}; diff --git a/src/shared/services/builder/cameraService.ts b/src/shared/services/builder/cameraService.ts index 356e6be..abfa56c 100644 --- a/src/shared/services/builder/cameraService.ts +++ b/src/shared/services/builder/cameraService.ts @@ -14,6 +14,11 @@ interface IcameraData { versionId: string; } interface IgetCameras { + organization: string; + projectId: string; + userId: string; +} +interface IOnline { organization: string; userId: string; } @@ -40,6 +45,7 @@ export const SetCamera = async ( if (!LivingProject) return { status: "Project not found" }; const existingCamera = await cameraModel(organization).findOne({ userId: userId, + isArchive: false, }); if (existingCamera) { const updateCamera = await cameraModel(organization).findOneAndUpdate( @@ -86,12 +92,14 @@ export const SetCamera = async ( export const GetCamers = async ( data: IgetCameras ): Promise<{ status: string; data?: Object }> => { - const { userId, organization } = data; + const { userId, organization, projectId } = data; try { const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; const findCamera = await cameraModel(organization).findOne({ userId: userId, + projectId: projectId, + isArchive: false, }); if (!findCamera) { return { status: "Camera not found" }; @@ -111,7 +119,7 @@ export const GetCamers = async ( } }; export const onlineActiveDatas = async ( - data: IgetCameras + data: IOnline ): Promise<{ status: string; data?: Object }> => { const { organization, userId } = data; try { @@ -119,11 +127,12 @@ export const onlineActiveDatas = async ( if (!UserExists) return { status: "User not found" }; const findactiveUsers = await UsersDataModel(organization).find({ activeStatus: "online", + isArchive: false, }); const cameraDataPromises = findactiveUsers.map(async (activeUser: any) => { const cameraData = await cameraModel(organization) - .findOne({ userId: activeUser._id }) + .findOne({ userId: activeUser._id, isArchive: false }) .select("position target rotation -_id"); if (cameraData) { @@ -143,7 +152,7 @@ export const onlineActiveDatas = async ( }); const cameraDatas = (await Promise.all(cameraDataPromises)).filter( - (singledata: any) => singledata !== null + (singledata: unknown) => singledata !== null ); return { status: "Success", data: cameraDatas }; diff --git a/src/shared/services/builder/lineService.ts b/src/shared/services/builder/lineService.ts index 0f8f175..4894d28 100644 --- a/src/shared/services/builder/lineService.ts +++ b/src/shared/services/builder/lineService.ts @@ -8,7 +8,11 @@ interface ILineItems { projectId: string; userId: string; } - +interface ILineGet { + organization: string; + projectId: string; + userId: string; +} interface ILineUpdate { organization: string; uuid: number; @@ -67,19 +71,14 @@ export const UpdateLineItems = async ( const { organization, projectId, uuid, position, userId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; - await lineModel(organization).updateMany( + const updateResult = await lineModel(organization).updateMany( { "line.uuid": uuid, projectId: projectId }, { $set: { "line.$.position": position } } ); - // return { - // success: true, - // status: "line updated", - // data: { uuid: uuid, position: position }, - // organization: organization, - // }; + return { status: "Success", - data: { uuid: uuid, position: position }, + data: updateResult, }; } catch (error: unknown) { if (error instanceof Error) { @@ -103,9 +102,9 @@ export const DeleteLineItems = async ( const inputUuids = line.map((item: any) => item.uuid); const findValue = await lineModel(organization).findOneAndDelete( - { projectId: projectId }, + { projectId: projectId, isArchive: false }, { - "line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key + "line.uuid": { $all: inputUuids }, } ); @@ -113,22 +112,11 @@ export const DeleteLineItems = async ( return { status: "line not found", }; - // return { - // success: false, - // message: "line not found", - // organization: organization, - // }; } else { return { status: "Success", data: findValue, }; - // return { - // success: true, - // message: "line deleted", - // data: findValue, - // organization: organization, - // }; } } catch (error: unknown) { if (error instanceof Error) { @@ -152,11 +140,11 @@ export const DeleteLayer = async ( const findValue = await lineModel(organization).find({ layer: layer, projectId: projectId, + isArchive: false, }); if (!findValue) { return { status: "layer not found" }; - // return { success: false, message: "layer not found" }; } else { await lineModel(organization).deleteMany( { projectId: projectId }, @@ -171,12 +159,6 @@ export const DeleteLayer = async ( status: "Success", data: updateResult, }; - // return { - // success: true, - // message: "layer deleted", - // data: layer, - // organization: organization, - // }; } } catch (error: unknown) { if (error instanceof Error) { @@ -191,6 +173,34 @@ export const DeleteLayer = async ( } }; +export const GetLinesService = async ( + data: ILineGet +): 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 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 }> => { @@ -199,7 +209,7 @@ export const DeleteLinePoints = async ( const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; const findValue = await lineModel(organization).deleteMany( - { projectId: projectId }, + { projectId: projectId, isArchive: false }, { "line.uuid": uuid, } @@ -207,19 +217,8 @@ export const DeleteLinePoints = async ( if (!findValue) { return { status: "Line not found" }; - // return { - // success: false, - // message: "line not found", - // organization: organization, - // }; } else { return { status: "Success" }; - // return { - // success: true, - // message: "point deleted", - // data: uuid, - // organization: organization, - // }; } } catch (error: unknown) { if (error instanceof Error) { diff --git a/src/shared/services/builder/wallService.ts b/src/shared/services/builder/wallService.ts index fbe3b13..3ec6824 100644 --- a/src/shared/services/builder/wallService.ts +++ b/src/shared/services/builder/wallService.ts @@ -49,11 +49,12 @@ export class WallItems { if (!UserExists) return { status: "User not found" }; const findvalue = await wallItemModel(organization).findOne({ modelUuid: modelUuid, + isArchive: false, }); if (findvalue) { const updatevalue = await wallItemModel(organization).findOneAndUpdate( - { modelUuid: modelUuid, projectId: projectId }, + { modelUuid: modelUuid, projectId: projectId, isArchive: false }, { modelName, position, @@ -63,13 +64,12 @@ export class WallItems { quaternion, scale, }, - { new: true } // Return the updated document + { new: true } ); return { status: "Updated successfully", data: updatevalue, }; - // res.status(201).json(updatevalue); } else { const newValue = await wallItemModel(organization).create({ modelUuid, @@ -86,7 +86,6 @@ export class WallItems { status: "wall Item created successfully", data: newValue, }; - // res.status(201).json(newValue); } } catch (error: unknown) { if (error instanceof Error) { @@ -107,6 +106,7 @@ export class WallItems { if (!UserExists) return { status: "User not found" }; const findValue = await wallItemModel(organization).find({ projectId: projectId, + isArchive: false, }); if (!findValue) { return { @@ -139,6 +139,7 @@ export class WallItems { modelUuid: modelUuid, modelName: modelName, projectId: projectId, + isArchive: false, }); if (!findValue) { return { diff --git a/src/shared/services/builder/zoneService.ts b/src/shared/services/builder/zoneService.ts index 9204a85..9174dfe 100644 --- a/src/shared/services/builder/zoneService.ts +++ b/src/shared/services/builder/zoneService.ts @@ -24,12 +24,18 @@ interface IZone { 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; } @@ -51,7 +57,7 @@ export const SetZone = async (data: ISetZone): Promise => { if (findZoneId) { const updateZone = await zoneModel(organization) .findOneAndUpdate( - { zoneId: zoneId, projectId: projectId }, + { zoneId: zoneId, projectId: projectId, isArchive: false }, { points: points, viewPortposition: viewPortposition, @@ -60,7 +66,6 @@ export const SetZone = async (data: ISetZone): Promise => { { new: true } ) .select("-_id -__v"); - // return { success: true, message: 'zone updated', data: updateZone, organization: organization } return { status: "zone updated", data: updateZone }; } else { const zoneCreate = await zoneModel(organization).create({ @@ -76,7 +81,6 @@ export const SetZone = async (data: ISetZone): Promise => { const createdZone = await zoneModel(organization) .findById(zoneCreate._id) .select("-_id -__v"); - // return { success: true, status: 'zone created', data: createdZone, organization: organization } return { status: "Success", data: createdZone }; } } catch (error: unknown) { @@ -97,6 +101,7 @@ export const DelZone = async (data: IZone): Promise => { 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" }; @@ -110,7 +115,10 @@ export const DelZone = async (data: IZone): Promise => { }) .select("-_id -__v"); if (deleteZone) { - const panels = await panelModel(organization).find({ zoneId }); + const panels = await panelModel(organization).find({ + zoneId, + isArchive: false, + }); const allWidgetIds = panels.reduce((ids: string[], panel: any) => { return ids.concat(panel.widgets || []); @@ -122,32 +130,26 @@ export const DelZone = async (data: IZone): Promise => { ); await panelModel(organization).updateMany( - { zoneId }, + { zoneId, isArchive: false }, { $set: { isArchive: true } } ); await Promise.all([ widget3dModel(organization).updateMany( - { zoneId }, + { zoneId, isArchive: false }, { $set: { isArchive: true } } ), templateModel(organization).updateMany( - { zoneId }, + { zoneId, isArchive: false }, { $set: { isArchive: true } } ), floatWidgetModel(organization).updateMany( - { zoneId }, + { zoneId, isArchive: false }, { $set: { isArchive: true } } ), ]); } - // return { - // success: true, - // message: "zone deleted", - // data: deleteZone, - // organization: organization, - // }; return { status: "Success", data: deleteZone, @@ -156,11 +158,6 @@ export const DelZone = async (data: IZone): Promise => { return { status: "Invalid zone ID", }; - // return { - // success: true, - // message: "Invalid zone ID", - // organization: organization, - // }; } } catch (error: unknown) { if (error instanceof Error) { @@ -176,21 +173,19 @@ export const DelZone = async (data: IZone): Promise => { }; export const GetZones = async (data: IGetZones): Promise => { try { - const { organization, userId } = data; + const { organization, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; const findZoneId = await zoneModel(organization) - .find() + .find({ projectId: projectId, isArchive: false }) .select( "zoneId zoneName layer points viewPortCenter viewPortposition -_id" ); if (!findZoneId) { return { status: "Invalid zone" }; - // res.status(500).json({ message: "Invalid zone" }); } return { status: "Success", data: findZoneId }; - // res.status(200).json({ data: findZoneId, organization: organization }); } catch (error: unknown) { if (error instanceof Error) { return { @@ -211,6 +206,7 @@ export const ZoneData = async (data: IZone): Promise => { const findZone = await zoneModel(organization).findOne({ zoneId: zoneId, projectId: projectId, + isArchive: false, }); if (findZone) return { @@ -220,7 +216,6 @@ export const ZoneData = async (data: IZone): Promise => { else { return { status: "Zone not found" }; } - // if (findZone) return res.status(200).json(findZone); } catch (error: unknown) { if (error instanceof Error) { return { @@ -249,7 +244,6 @@ export const SingleZonePanelData = async (data: IZone): Promise => { ); if (!existingZone) { return { status: "Zone not found for the UUID" }; - // return res.send({ message: "Zone not found for the UUID" }); } else { const panelData = await panelModel(organization).find({ zoneId: zoneId, @@ -289,7 +283,6 @@ export const SingleZonePanelData = async (data: IZone): Promise => { }; return { status: "Success", data: objectData }; - // return res.status(200).json(objectData); } } catch (error: unknown) { if (error instanceof Error) { @@ -303,9 +296,9 @@ export const SingleZonePanelData = async (data: IZone): Promise => { } } }; -export const VizZoneDatas = async (data: IZone): Promise => { +export const VizZoneDatas = async (data: IVizZone): Promise => { try { - const { organization, userId, projectId, zoneId } = data; + const { organization, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; const existingZones = await zoneModel(organization) @@ -318,7 +311,6 @@ export const VizZoneDatas = async (data: IZone): Promise => { ); if (!existingZones) { return { status: "Zone not found for the UUID" }; - // return res.send({ message: "Zone not found for the UUID" }); } else { const response = await Promise.all( existingZones.map(async (zone) => { @@ -327,7 +319,6 @@ export const VizZoneDatas = async (data: IZone): Promise => { isArchive: false, }); - // Fetch widgets for each panel const widgets = await Promise.all( panelData.map(async (panel) => { const widgetDataArray = await widgetModel(organization).find({ @@ -360,7 +351,6 @@ export const VizZoneDatas = async (data: IZone): Promise => { ); return { status: "Success", data: response }; - // return res.status(200).json(response); } } catch (error: unknown) { if (error instanceof Error) { diff --git a/src/shared/services/project/project-Services.ts b/src/shared/services/project/project-Services.ts index c71b982..9bb3ab3 100644 --- a/src/shared/services/project/project-Services.ts +++ b/src/shared/services/project/project-Services.ts @@ -1,6 +1,5 @@ import projectModel from "../../model/project/project-model.ts"; import userModel from "../../model/user-Model.ts"; -import { Types } from "mongoose"; import versionModel from "../../model/version/versionModel.ts"; import { existingProject, diff --git a/src/shared/services/trash/trashService.ts b/src/shared/services/trash/trashService.ts index 2976f95..99cb305 100644 --- a/src/shared/services/trash/trashService.ts +++ b/src/shared/services/trash/trashService.ts @@ -1,15 +1,19 @@ import projectModel from "../../model/project/project-model.ts"; +import { existingUser } from "../helpers/v1projecthelperFns.ts"; interface IOrg { organization: string; + userId: string; } interface IRestore { projectId: string; organization: string; + userId: string; } export const TrashDatas = async (data: IOrg) => { 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({ isArchive: true, isDeleted: false, @@ -47,7 +51,9 @@ export const TrashDatas = async (data: IOrg) => { }; export const RestoreTrashData = async (data: IRestore) => { 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({ _id: projectId, isArchive: true, @@ -64,3 +70,25 @@ export const RestoreTrashData = async (data: IRestore) => { 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 }; + } +}; diff --git a/src/shared/services/visualization/floatWidgetService.ts b/src/shared/services/visualization/floatWidgetService.ts index ca708e0..d3a6c2c 100644 --- a/src/shared/services/visualization/floatWidgetService.ts +++ b/src/shared/services/visualization/floatWidgetService.ts @@ -81,11 +81,6 @@ export const AddFloat = async (data: IAddFloatData): Promise => { projectId: projectId, }); if (!existingZone) return { status: "Zone not found for the zoneId" }; - // return { - // success: false, - // message: "Zone not found for the zoneId", - // organization: organization, - // }; const existingFloatWidget = await floatWidgetModel(organization).findOne({ floatWidgetID: widget.id, @@ -122,12 +117,6 @@ export const AddFloat = async (data: IAddFloatData): Promise => { zoneName: existingZone.zoneName, }; return { status: "Widget updated successfully", data: floatUpdateDatas }; - // return { - // success: true, - // message: "Widget updated successfully", - // data: floatUpdateDatas, - // organization: organization, - // }; } else { const newFloadWidget = await floatWidgetModel(organization).create({ className: widget.className, @@ -153,12 +142,6 @@ export const AddFloat = async (data: IAddFloatData): Promise => { zoneName: existingZone.zoneName, }; return { status: "Success", data: floatDatas }; - // return { - // success: true, - // message: "FloatWidget created successfully", - // data: floatDatas, - // organization: organization, - // }; } return { status: "Failed to create FloatWidget" }; } @@ -186,22 +169,12 @@ export const DelFloat = async (data: IDelFloat): Promise => { projectId: projectId, }); if (!existingZone) return { status: "Zone not found for the zoneId" }; - // return { - // success: false, - // message: "Zone not found for the zoneId", - // organization: organization, - // }; const findfloatWidget = await floatWidgetModel(organization).findOne({ floatWidgetID: floatWidgetID, isArchive: false, }); if (!findfloatWidget) return { status: "FloatWidget not found for the Id" }; - // return { - // success: false, - // message: "Zone not found for the zoneId", - // organization: organization, - // }; const widgetData = await floatWidgetModel(organization).findByIdAndUpdate( { _id: findfloatWidget._id, isArchive: false }, { isArchive: true }, @@ -215,12 +188,6 @@ export const DelFloat = async (data: IDelFloat): Promise => { zoneName: existingZone.zoneName, }; return { status: "Success", data: floatDeleteData }; - // return { - // success: true, - // message: "FloatingWidget deleted successfully", - // data: floatDeleteData, - // organization: organization, - // }; } return { status: "FloatWidget not deleted" }; } catch (error: unknown) { @@ -248,13 +215,7 @@ export const DuplicateFloat = async ( isArchive: false, projectId: projectId, }); - if (!existingZone) - // return { - // success: false, - // message: "Zone not found for the zoneId", - // organization: organization, - // }; - return { status: "Zone not found for the zoneId" }; + if (!existingZone) return { status: "Zone not found for the zoneId" }; const existingFloatWidget = await floatWidgetModel(organization).findOne({ floatWidgetID: widget.id, @@ -285,12 +246,6 @@ export const DuplicateFloat = async ( } ); if (!updateFloatWidget) { - // return { - // success: false, - // message: "FloatWidget update unsuccessfull", - // // data: updateWidget, - // organization: organization, - // }; return { status: "FloatWidget update unsuccessfull" }; } const floatUpdateDatas = { @@ -303,12 +258,6 @@ export const DuplicateFloat = async ( status: "Widget updated successfully", data: floatUpdateDatas, }; - // return { - // success: true, - // message: "Widget updated successfully", - // data: floatUpdateDatas, - // organization: organization, - // }; } const newFloadWidget = await floatWidgetModel(organization).create({ className: widget.className, @@ -341,12 +290,6 @@ export const DuplicateFloat = async ( status: "Success", data: floatDatas, }; - // return { - // success: true, - // message: "duplicate FloatWidget created successfully", - // data: floatDatas, - // organization: organization, - // }; } return { status: "Failed to duplicate FloatWidget", @@ -383,7 +326,6 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise => { .select("-_id -zoneId -createdAt -updatedAt -__v"); if (!widgetData || widgetData.length === 0) { return { status: "All Datas" }; - // return res.send([]); } const formattedWidgets = widgetData.map((widget) => ({ @@ -400,7 +342,6 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise => { value: widget.value, })); return { status: "Success", data: formattedWidgets }; - // return res.status(200).json(formattedWidgets); } catch (error: unknown) { if (error instanceof Error) { return { @@ -428,7 +369,6 @@ export const SingleFloatWidget = async ( .select("-_id -zoneId -createdAt -updatedAt -__v"); if (!widgetData || widgetData.length === 0) { return { status: "Widget not found" }; - // return res.status(204).json({ message: "Widget not found" }); } const Datastructure = { measurements: widgetData?.Data?.measurements || {}, @@ -436,7 +376,6 @@ export const SingleFloatWidget = async ( }; const header = widgetData?.header; return { status: "Success", data: { Datastructure, header } }; - // return res.status(200).json({ Data: Datastructure, header }); } catch (error: unknown) { if (error instanceof Error) { return { diff --git a/src/shared/services/visualization/panelService.ts b/src/shared/services/visualization/panelService.ts index 21b2975..98326ed 100644 --- a/src/shared/services/visualization/panelService.ts +++ b/src/shared/services/visualization/panelService.ts @@ -69,11 +69,6 @@ export const AddPanel = async (data: IAddPanel): Promise => { if (createdPanels.length === 0) { return { status: "No new panels were created. All panels already exist" }; - // return { - // success: false, - // message: "No new panels were created. All panels already exist", - // organization: organization, - // }; } const zoneAndPanelData = await getZoneAndPanelData( @@ -85,12 +80,6 @@ export const AddPanel = async (data: IAddPanel): Promise => { return zoneAndPanelData; } return { status: "Success", data: zoneAndPanelData }; - // return { - // success: true, - // message: "Panels created successfully", - // data: zoneAndPanelData, - // organization: organization, - // }; } catch (error: unknown) { if (error instanceof Error) { return { @@ -120,11 +109,7 @@ export const DelPanel = async (data: IPanel): Promise => { isArchive: false, }); if (!existingPanel) return { status: "Panel Already Deleted" }; - // return { - // success: false, - // message: "Panel Already Deleted", - // organization: organization, - // }; + await panelModel(organization).updateOne( { _id: existingPanel._id, isArchive: false }, { $set: { isArchive: true } } @@ -154,12 +139,6 @@ export const DelPanel = async (data: IPanel): Promise => { return zoneAndPanelData; } return { status: "Success", data: zoneAndPanelData }; - // return { - // success: true, - // message: "Panel deleted successfully", - // data: zoneAndPanelData, - // organization: organization, - // }; } catch (error: unknown) { if (error instanceof Error) { return { @@ -189,22 +168,13 @@ export const ClearPanel = async (data: IPanel): Promise => { isArchive: false, }); if (!existingPanel) return { status: "Requested Panel not found" }; - // return { - // success: false, - // message: "Requested Panel not found", - // organization: organization, - // }; const existingWidgets = await widgetModel(organization).find({ panelID: existingPanel._id, isArchive: false, }); if (existingWidgets.length === 0) return { status: "No widgets to clear" }; - // return { - // success: false, - // message: "No widgets to clear", - // organization: organization, - // }; + const clearWidgetsofPanel = await widgetModel(organization).updateMany( { panelID: existingPanel._id, isArchive: false }, { isArchive: true } @@ -218,11 +188,6 @@ export const ClearPanel = async (data: IPanel): Promise => { ); if (!clearWidgetsofPanel && !removeWidgetsInPanel) return { status: "Failed to clear widgets in panel" }; - // return { - // success: false, - // message: "Failed to clear widgets in panel", - // organization: organization, - // }; const zoneAndPanelData = await getZoneAndPanelData( organization, @@ -232,12 +197,7 @@ export const ClearPanel = async (data: IPanel): Promise => { if (!zoneAndPanelData) { return zoneAndPanelData; } - // return { - // success: true, - // data: zoneAndPanelData, - // message: "PanelWidgets cleared successfully", - // organization: organization, - // }; + return { status: "Success", data: zoneAndPanelData, @@ -286,12 +246,6 @@ export const LockedPanel = async (data: ILockedPanel): Promise => { status: "Success", data: zoneAndPanelData, }; - // return { - // success: true, - // message: "locked panel updated successfully", - // data: zoneAndPanelData, - // organization: organization, - // }; } return { status: "locked panel not updated" }; } @@ -324,11 +278,6 @@ const getZoneAndPanelData = async ( ); if (!existingZone) { return { status: "Zone not found" }; - // return { - // success: false, - // message: "Zone not found", - // organization: organization, - // }; } else { const panelData = await panelModel(organization).find({ zoneId: zoneId, @@ -371,11 +320,5 @@ const getZoneAndPanelData = async ( } } catch (error: unknown) { return { status: "Panel not found" }; - // return { - // success: false, - // message: "Panel not found", - // error, - // organization: organization, - // }; } }; diff --git a/src/shared/services/visualization/templateService.ts b/src/shared/services/visualization/templateService.ts index 52e032c..4b9a503 100644 --- a/src/shared/services/visualization/templateService.ts +++ b/src/shared/services/visualization/templateService.ts @@ -51,7 +51,6 @@ export const AddTemplate = async (data: IAddTemplate): Promise => { projectId: projectId, }); if (existingTemplate) return { status: "TemplateID alreay exists" }; - // return res.json({ message: "TemplateID alreay exists" }); const newTemplate = await templateModel(organization).create({ templateID: template.id, templateName: template.name, @@ -62,7 +61,6 @@ export const AddTemplate = async (data: IAddTemplate): Promise => { Widgets3D: template.Widgets3D, }); if (newTemplate) { - // return res.status(200).json({ message: "Template saved successfully" }); const allTemplateDatas = await templateModel(organization) .find({ isArchive: false }) .select("-_id -__v -isArchive -createdAt -updatedAt"); @@ -77,12 +75,6 @@ export const AddTemplate = async (data: IAddTemplate): Promise => { snapshot: data.snapshot, })); return { status: "Success", data: formattedTemplates }; - // return { - // success: true, - // message: "Template saved successfully", - // data: formattedTemplates, - // organization: organization, - // }; } return { status: "Template not saved" }; } catch (error: unknown) { @@ -113,11 +105,6 @@ export const AddTemplateToZone = async ( return { status: "Zone not found ", }; - // return { - // success: false, - // message: "Zone not found ", - // organization: organization, - // }; const existingTemplate = await templateModel(organization).findOne({ templateID: templateID, @@ -128,16 +115,10 @@ export const AddTemplateToZone = async ( return { status: "TemplateID not found", }; - // return { - // success: false, - // message: "TemplateID not found", - // organization: organization, - // }; if (existingZone.panelOrder.length > 0) { existingZone.panelOrder = existingTemplate.panelOrder; await existingZone.save(); - // Clear existing data before adding new data const archivePanelDatas = await panelModel(organization).find({ zoneId, isArchive: false, @@ -164,13 +145,13 @@ export const AddTemplateToZone = async ( isArchive: false, }); const existingPanelNames = existingPanels.map( - (panel: any) => panel.panelName + (panel) => panel.panelName as string ); const missingPanels = existingTemplate.panelOrder.filter( (panelName: string) => !existingPanelNames.includes(panelName) ); - const createdPanels = await Promise.all( + await Promise.all( missingPanels.map((panelName: any) => panelModel(organization).create({ zoneId, @@ -240,12 +221,6 @@ export const AddTemplateToZone = async ( }; return { status: "Success", data: templateZoneDatas }; - // return { - // success: true, - // message: "Template placed in Zone", - // data: templateZoneDatas, - // organization: organization, - // }; } catch (error: unknown) { if (error instanceof Error) { return { @@ -279,12 +254,6 @@ export const TemplateDelete = async (data: ITemplate): Promise => { status: "Success", data: TemplateDeleteData, }; - // return { - // success: true, - // message: "Template deleted successfully", - // data: TemplateDeleteData, - // organization: organization, - // }; } return { status: "Template not Deleted" }; } @@ -310,7 +279,6 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise => { .find({ projectId: projectId, isArchive: false }) .select("-_id -__v -isArchive -createdAt -updatedAt"); if (!templateDatas) return { status: "All Datas" }; - // return res.status(200).send([]); const formattedTemplates = templateDatas.map((data) => ({ id: data.templateID, @@ -322,7 +290,6 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise => { snapshot: data.snapshot, })); return { status: "Success", data: formattedTemplates }; - // return res.status(200).json(formattedTemplates); } catch (error: unknown) { if (error instanceof Error) { return { diff --git a/src/shared/services/visualization/widget3dService.ts b/src/shared/services/visualization/widget3dService.ts index bccaf3a..9eb6385 100644 --- a/src/shared/services/visualization/widget3dService.ts +++ b/src/shared/services/visualization/widget3dService.ts @@ -53,11 +53,7 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise => { projectId: projectId, }); if (!existingZone) return { status: "Zone not found for the zoneId" }; - // return { - // success: false, - // message: "Zone not found for the zoneId", - // organization: organization, - // }; + const existing3Dwidget = await widget3dModel(organization).findOne({ widgetID: widget.id, isArchive: false, @@ -76,17 +72,7 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise => { return { status: "3dwidget update successfully", }; - // return { - // success: true, - // message: "widget update successfully", - // organization: organization, - // }; } else return { status: "3dWidget not updated" }; - // return { - // success: false, - // message: "Widget not updated", - // organization: organization, - // }; } else { const newWidget3d = await widget3dModel(organization).create({ type: widget.type, @@ -115,12 +101,6 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise => { }; } return { status: "Widget 3d not created" }; - // return { - // success: true, - // message: "Widget created successfully", - // data: widgemodel3D_Datas, - // organization: organization, - // }; } } catch (error: unknown) { if (error instanceof Error) { @@ -149,11 +129,7 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise => { return { status: "Zone not found", }; - // return { - // success: false, - // message: "Zone not found", - // organization: organization, - // }; + const existing3Dwidget = await widget3dModel(organization).findOne({ widgetID: id, zoneId: zoneId, @@ -183,21 +159,10 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise => { status: "Success", data: updateDatas, }; - // return { - // success: true, - // message: "widget update successfully", - // data: updateDatas, - // organization: organization, - // }; } return { status: "Widget not updated" }; } else { return { status: "widget not found" }; - // return { - // success: false, - // message: "widget not found", - // organization: organization, - // }; } } catch (error: unknown) { if (error instanceof Error) { @@ -227,11 +192,7 @@ export const Delete3Dwidget = async ( return { status: "Zone not found", }; - // return { - // success: false, - // message: "Zone not found", - // organization: organization, - // }; + const existing3Dwidget = await widget3dModel(organization).findOne({ widgetID: id, isArchive: false, @@ -239,11 +200,6 @@ export const Delete3Dwidget = async ( }); if (!existing3Dwidget) { return { status: "3D widget not found for the ID" }; - // return { - // success: false, - // message: "3D widget not found for the ID", - // organization: organization, - // }; } const updateWidget = await widget3dModel(organization).findOneAndUpdate( { @@ -263,12 +219,6 @@ export const Delete3Dwidget = async ( status: "Success", data: delete_Datas, }; - // return { - // success: true, - // data: delete_Datas, - // message: "3DWidget delete successfull", - // organization: organization, - // }; } return { status: "3DWidget delete unsuccessfull" }; } catch (error: unknown) { @@ -297,14 +247,12 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise => { return { status: "Zone not found", }; - // return res.send("Zone not found"); const widgetData = await widget3dModel(organization).find({ zoneId: zoneId, isArchive: false, }); if (!widgetData || widgetData.length === 0) { return { status: "All 3Dwidgets" }; - // return res.json([]); } const zonebasedWidget = widgetData.map((widget) => ({ @@ -318,7 +266,6 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise => { rotation: widget?.rotation, })); return { status: "Success", data: zonebasedWidget }; - // return res.status(200).json(zonebasedWidget); } catch (error: unknown) { if (error instanceof Error) { return { diff --git a/src/shared/services/visualization/widgetService.ts b/src/shared/services/visualization/widgetService.ts index 0474c79..9493044 100644 --- a/src/shared/services/visualization/widgetService.ts +++ b/src/shared/services/visualization/widgetService.ts @@ -1,7 +1,10 @@ import widgetModel from "../../V1Models/Vizualization/widgemodel.ts"; import zoneModel from "../../V1Models/Builder/zoneModel.ts"; import panelModel from "../../V1Models/Vizualization/panelmodel.ts"; -import { existingUser } from "../helpers/v1projecthelperFns.ts"; +import { + existingProjectById, + existingUser, +} from "../helpers/v1projecthelperFns.ts"; interface IResult { status: string; data?: object; @@ -29,11 +32,44 @@ interface IWidgetDelete { 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 => { 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, @@ -47,18 +83,12 @@ export const AddWidget = async (data: IWidgetCreate): Promise => { isArchive: false, }); if (!existingPanel) return { status: "panelName not found" }; - // return { - // success: false, - // message: "panelName not found", - // organization: organization, - // }; if (existingPanel.panelName === widget.panel) { const existingWidget = await widgetModel(organization).findOne({ panelID: existingPanel._id, widgetID: widget.id, isArchive: false, - // widgetOrder: widget.widgetOrder, }); if (existingWidget) { const updateWidget = await widgetModel(organization).findOneAndUpdate( @@ -78,29 +108,16 @@ export const AddWidget = async (data: IWidgetCreate): Promise => { isArchive: false, }, }, - { upsert: true, new: true } // Upsert: create if not exists, new: return updated document + { upsert: true, new: true } ); if (!updateWidget) { return { status: "Widget update unsuccessfull" }; - // return { - // success: false, - // message: "Widget update unsuccessfull", - // // data: updateWidget, - // organization: organization, - // }; } return { status: "Widget update successfully", data: updateWidget }; - // return { - // success: true, - // message: "Widget updated successfully", - // data: updateWidget, - // organization: organization, - // }; } const newWidget = await widgetModel(organization).create({ widgetID: widget.id, elementType: widget.type, - // widgetOrder: widgetOrder, widgetName: widget.title, panelID: existingPanel._id, widgetside: widget.panel, @@ -128,22 +145,11 @@ export const AddWidget = async (data: IWidgetCreate): Promise => { status: "Success", data: finaldata, }; - // return { - // success: true, - // message: "Widget created successfully", - // data: finaldata, - // organization: organization, - // }; } } return { status: "Type mismatch", }; - // return { - // success: false, - // message: "Type mismatch", - // organization: organization, - // }; } catch (error: unknown) { if (error instanceof Error) { return { @@ -161,6 +167,12 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise => { 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, @@ -174,11 +186,7 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise => { isArchive: false, }); if (!findWidget) return { status: "Widget not found" }; - // return { - // success: false, - // message: "Widget not found", - // organization: organization, - // }; + const widgetData = await widgetModel(organization).updateOne( { _id: findWidget._id, isArchive: false, zoneId: zoneId }, { $set: { isArchive: true } } @@ -223,12 +231,6 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise => { zoneName: existingZone.zoneName, }; return { status: "Success", data: widgetData1 }; - // return { - // success: true, - // message: "Widget deleted successfully", - // data: widgetData1, - // organization: organization, - // }; } return { status: "Widget not found" }; } catch (error: unknown) { @@ -243,3 +245,112 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise => { } } }; +export const UpdateWidget = async (data: IWidgetUpdate): Promise => { + 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 => { + 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", + }; + } + } +};