From 2bb3814d7562b43482d6f53b32a83aca5064afb9 Mon Sep 17 00:00:00 2001 From: Nivetharamesh Date: Thu, 29 May 2025 19:11:26 +0530 Subject: [PATCH] New version API collaboration and tested for Project --- src/api-server/Routes/homepageRoutes.ts | 12 ++- .../builderController/v1LineController.ts | 30 +++++++ .../builderController/v1assetController.ts | 4 +- .../builderController/v1cameraController.ts | 29 ++++--- .../builderController/v1wallController.ts | 27 ++++++- .../builderController/v1zoneController.ts | 32 +++++++- .../homeController/v1homeController.ts | 2 +- .../projectController/v1projectController.ts | 72 ++++++++++++++--- .../trashController/v1trashController.ts | 15 ++-- .../v1floatWidgetController.ts | 20 +++++ .../v1panelController.ts | 20 +++++ .../v1templateController.ts | 20 +++++ .../v1widgetController.ts | 20 +++++ .../widget3Dcontroller.ts | 20 +++++ .../V1/v1Routes/v1-projectRoutes.ts | 12 ++- src/api-server/V1/v1Routes/v1-trashRoutes.ts | 5 +- .../services/helpers/v1projecthelperFns.ts | 5 +- src/shared/services/trash/trashService.ts | 33 +------- .../services/v1Project/v1projectservice.ts | 81 ++++++++++++++++++- src/shared/services/v1home/v1homeservice.ts | 9 ++- src/shared/services/v1trash/v1trashservice.ts | 26 ++++++ .../visualization/floatWidgetService.ts | 30 ++++++- .../services/visualization/panelService.ts | 31 ++++++- .../services/visualization/templateService.ts | 29 ++++++- .../services/visualization/widget3dService.ts | 30 ++++++- 25 files changed, 526 insertions(+), 88 deletions(-) diff --git a/src/api-server/Routes/homepageRoutes.ts b/src/api-server/Routes/homepageRoutes.ts index 8d5214d..b2639c4 100644 --- a/src/api-server/Routes/homepageRoutes.ts +++ b/src/api-server/Routes/homepageRoutes.ts @@ -1,11 +1,17 @@ import * as express from "express"; -import { recentDataController, searchProjectController, searchTrashProjectController } from "../controller/home/homeControllers.ts"; -import { searchTrashProject } from "../../shared/services/home/homeService.ts"; +import { + recentDataController, + searchProjectController, + searchTrashProjectController, +} from "../controller/home/homeControllers.ts"; import { tutorialsDataController } from "../controller/home/tutorialControllers.ts"; const homePageRouter = express.Router(); -homePageRouter.get("/RecentlyViewed/:userId/:organization", recentDataController); +homePageRouter.get( + "/RecentlyViewed/:userId/:organization", + recentDataController +); homePageRouter.get("/searchProjects", searchProjectController); homePageRouter.get("/searchTrashProjects", searchTrashProjectController); homePageRouter.get("/tutorials", tutorialsDataController); diff --git a/src/api-server/V1/v1Controllers/builderController/v1LineController.ts b/src/api-server/V1/v1Controllers/builderController/v1LineController.ts index 9c5308d..efab22f 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1LineController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1LineController.ts @@ -38,6 +38,11 @@ export const NewLineController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Success": res.status(201).json(result.data); break; @@ -81,6 +86,11 @@ export const UpdateLineController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Success": res.status(201).json(result.data); break; @@ -122,6 +132,11 @@ export const DeleteLineController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "line not found": res.status(404).json({ message: "data not found", @@ -168,6 +183,11 @@ export const DeleteLayerController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "layer not found": res.status(404).json({ message: "data not found", @@ -215,6 +235,11 @@ export const DeleteLinePointsController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Line not found": res.status(404).json({ message: "data not found", @@ -260,6 +285,11 @@ export const GetLinesController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Success": res.status(200).json(result.data); break; diff --git a/src/api-server/V1/v1Controllers/builderController/v1assetController.ts b/src/api-server/V1/v1Controllers/builderController/v1assetController.ts index ce110b3..7d19a63 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1assetController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1assetController.ts @@ -60,12 +60,12 @@ export const CreateAssetController = async ( switch (result.status) { case "User not found": - res.status(200).json({ + res.status(404).json({ message: "User not found", }); break; case "Project not found": - res.status(200).json({ + res.status(404).json({ message: "Project not found", }); break; diff --git a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts index 96d329c..efeaf61 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts @@ -40,22 +40,22 @@ export const SetNewCamera = async ( const result = await SetCamera(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", - TrashDatas: [], }); break; case "Update Success": - res.status(200).json({ - TrashDatas: result.data, - }); + res.status(200).json(result.data); break; case "Success": - res.status(200).json({ - TrashDatas: result.data, - }); + res.status(200).json(result.data); break; default: res.status(500).json({ @@ -90,16 +90,18 @@ export const CameraList = 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", - TrashDatas: [], }); break; case "Success": - res.status(200).json({ - TrashDatas: result.data, - }); + res.status(200).json(result.data); break; default: res.status(500).json({ @@ -136,6 +138,11 @@ export const ActiveOnlineController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Success": res.status(200).json(result.data); break; diff --git a/src/api-server/V1/v1Controllers/builderController/v1wallController.ts b/src/api-server/V1/v1Controllers/builderController/v1wallController.ts index 87155dc..bad4471 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1wallController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1wallController.ts @@ -56,7 +56,14 @@ export const WallSetup = async ( }); switch (result.status) { case "User not found": - res.status(404).json({ message: "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 "Updated successfully": res.status(200).json(result.data); @@ -96,7 +103,14 @@ export const WallGet = async ( switch (result.status) { case "User not found": - res.status(404).json({ message: "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 "wallitems not found": res.status(404).json({ @@ -141,7 +155,14 @@ export const WallDelete = async ( switch (result.status) { case "User not found": - res.status(404).json({ message: "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({ diff --git a/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts b/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts index 66e451b..462cf4e 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1zoneController.ts @@ -32,10 +32,15 @@ export const CreateZoneController = async ( switch (result.status) { case "User not found": - res.status(200).json({ + res.status(404).json({ message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "zone updated": res.status(200).json({ message: "zone updated", @@ -87,6 +92,11 @@ export const DeleteZoneController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Invalid zone ID": res.status(404).json({ message: "Zone not found for the UUID", @@ -134,6 +144,11 @@ export const GetZoneController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Invalid zone": res.status(404).json({ message: "Zone not found for the UUID", @@ -179,6 +194,11 @@ export const VizZoneController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found for the UUID": res.status(404).json({ message: "Zone not found for the UUID", @@ -226,6 +246,11 @@ export const ZoneDataController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -272,6 +297,11 @@ export const SingleZonePanelController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found for the UUID": res.status(404).json({ message: "Zone not found for the UUID", diff --git a/src/api-server/V1/v1Controllers/homeController/v1homeController.ts b/src/api-server/V1/v1Controllers/homeController/v1homeController.ts index ede617d..228b0ff 100644 --- a/src/api-server/V1/v1Controllers/homeController/v1homeController.ts +++ b/src/api-server/V1/v1Controllers/homeController/v1homeController.ts @@ -1,4 +1,4 @@ -import { Request, Response } from "express"; +import { Response } from "express"; import { RecentlyAdded, searchProject, diff --git a/src/api-server/V1/v1Controllers/projectController/v1projectController.ts b/src/api-server/V1/v1Controllers/projectController/v1projectController.ts index 0cc9c66..d37e095 100644 --- a/src/api-server/V1/v1Controllers/projectController/v1projectController.ts +++ b/src/api-server/V1/v1Controllers/projectController/v1projectController.ts @@ -1,7 +1,8 @@ -import { Request, Response } from "express"; +import { Response } from "express"; import { createProject, DeleteProject, + DuplicateProject, GetAllProjects, updateProject, viewProject, @@ -15,6 +16,7 @@ export const createProjectController = async ( try { const { userId, organization } = req.user || {}; const { projectUuid, thumbnail } = req.body; + if (!req.user || !req.user.userId || !req.user.organization) { res.status(401).json({ message: "Unauthorized" }); return; @@ -105,17 +107,12 @@ export const RemoveProject = async ( try { const { projectId } = req.params; // const { organization, userId } = req.body; - const { organization, userId, role } = req.user || {}; - if ( - !req.user || - !req.user.userId || - !req.user.organization || - !req.user.role - ) { + const { organization, userId } = req.user || {}; + if (!req.user || !req.user.userId || !req.user.organization) { res.status(401).json({ message: "Unauthorized" }); return; } - if (!projectId || !organization || !userId || !role) { + if (!projectId || !organization || !userId) { res.status(400).json({ message: "All fields are required", }); @@ -125,7 +122,6 @@ export const RemoveProject = async ( projectId, organization, userId, - role, }); switch (result?.status) { case "Project not found": @@ -267,3 +263,59 @@ export const ViewData = async ( return; } }; +export const ProjectDuplicateController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { userId, organization } = req.user || {}; + const { projectUuid, thumbnail, projectName } = req.body; + + if (!req.user || !req.user.userId || !req.user.organization) { + res.status(401).json({ message: "Unauthorized" }); + return; + } + if (!projectUuid || !thumbnail || !projectName) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await DuplicateProject({ + ...req.body, + userId, + organization, + }); + + switch (result.status) { + case "project_exists": + res.status(403).json({ + message: "Project already exists", + }); + break; + + case "user_not_found": + res.status(404).json({ + message: "User not found", + }); + break; + + case "Success": + res.status(201).json({ + message: "Project Duplicated Successfully", + projectId: result.project._id, + }); + 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/v1Controllers/trashController/v1trashController.ts b/src/api-server/V1/v1Controllers/trashController/v1trashController.ts index 1d7c3f8..944c763 100644 --- a/src/api-server/V1/v1Controllers/trashController/v1trashController.ts +++ b/src/api-server/V1/v1Controllers/trashController/v1trashController.ts @@ -1,7 +1,8 @@ -import { Request, Response } from "express"; +import { Response } from "express"; import { TrashDatas, RestoreTrashData, + TrashDelete, } from "../../../../shared/services/v1trash/v1trashservice.ts"; import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; @@ -107,7 +108,7 @@ export const RestoreTrash = async ( }); } }; -export const DeleteTrash = async ( +export const DeleteTrashData = async ( req: AuthenticatedRequest, res: Response ): Promise => { @@ -122,7 +123,7 @@ export const DeleteTrash = async ( }); return; } - const result = await RestoreTrashData({ + const result = await TrashDelete({ organization, projectId, role, @@ -140,14 +141,14 @@ export const DeleteTrash = async ( message: "Project not found", }); break; - case "Project Trash Delete unsuccessfull": + case "Project Already Deleted": res.status(200).json({ - message: "Project Trash Delete unsuccessfull", + message: "Project Already Deleted", }); break; - case "Trash Project Restored successfully": + case "Trash Project Delete successfully": res.status(200).json({ - message: "Trash Project Restored successfully", + message: "Trash Project Delete successfully", }); break; default: diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts index dba9ba9..022020b 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts @@ -43,6 +43,11 @@ export const FloatAddController = async ( 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", @@ -102,6 +107,11 @@ export const DeleteFloatController = async ( 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", @@ -169,6 +179,11 @@ export const DuplicateFloatController = async ( 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", @@ -232,6 +247,11 @@ export const GetFloatController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1panelController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1panelController.ts index 12adb8b..494b449 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1panelController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1panelController.ts @@ -34,6 +34,11 @@ export const AddPanelController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -89,6 +94,11 @@ export const DeletePanelController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -143,6 +153,11 @@ export const ClearPanelController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -202,6 +217,11 @@ export const LockedPanelController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1templateController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1templateController.ts index b044051..81ff971 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1templateController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1templateController.ts @@ -33,6 +33,11 @@ export const AddTemplateController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "TemplateID alreay exists": res.status(200).json({ message: "TemplateID alreay exists", @@ -87,6 +92,11 @@ export const AddTemToZoneController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -141,6 +151,11 @@ export const TemplateDeleteController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Template not found": res.status(404).json({ message: "Template not found", @@ -193,6 +208,11 @@ export const GetTemplateController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "All Datas": res.status(404).json([]); break; diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts index bc75b63..a9d0b98 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts @@ -34,6 +34,11 @@ export const AddWidgetController = async ( 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", @@ -102,6 +107,11 @@ export const WidgetDeleteController = async ( 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", @@ -169,6 +179,11 @@ export const WidgetUpdateController = async ( message: "Project 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", @@ -232,6 +247,11 @@ export const GetWidgetController = async ( message: "Project 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", diff --git a/src/api-server/V1/v1Controllers/vizualizationController/widget3Dcontroller.ts b/src/api-server/V1/v1Controllers/vizualizationController/widget3Dcontroller.ts index 41defc8..d1f0c87 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/widget3Dcontroller.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/widget3Dcontroller.ts @@ -34,6 +34,11 @@ export const Add3dWidgetController = async ( 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(200).json({ message: "Zone not found", @@ -108,6 +113,11 @@ export const Update3DwidgetController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -167,6 +177,11 @@ export const Delete3DwidgetController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", @@ -225,6 +240,11 @@ export const Get3DWidgetController = async ( message: "User not found", }); break; + case "Project not found": + res.status(404).json({ + message: "Project not found", + }); + break; case "Zone not found": res.status(404).json({ message: "Zone not found", diff --git a/src/api-server/V1/v1Routes/v1-projectRoutes.ts b/src/api-server/V1/v1Routes/v1-projectRoutes.ts index 2f34d24..fedb1a8 100644 --- a/src/api-server/V1/v1Routes/v1-projectRoutes.ts +++ b/src/api-server/V1/v1Routes/v1-projectRoutes.ts @@ -2,6 +2,7 @@ import express from "express"; import { createProjectController, GetProjects, + ProjectDuplicateController, RemoveProject, updateProjectController, ViewData, @@ -12,7 +13,12 @@ import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; const v1projectRouter = express.Router(); // project -v1projectRouter.post("/upsertProject", tokenValidator, createProjectController); +v1projectRouter.post("/NewProject", tokenValidator, createProjectController); +v1projectRouter.post( + "/project/Duplicate", + tokenValidator, + ProjectDuplicateController +); v1projectRouter.get( "/Projects", tokenValidator, @@ -20,14 +26,14 @@ v1projectRouter.get( GetProjects ); v1projectRouter.patch( - "/Project/archive/:projectId", + "/Projects/Archive/:projectId", tokenValidator, // authorizedRoles("Admin", "User"), RemoveProject ); v1projectRouter.patch( - "/Project/:projectId", + "/Projects/:projectId", tokenValidator, // authorizedRoles("Admin", "User"), updateProjectController diff --git a/src/api-server/V1/v1Routes/v1-trashRoutes.ts b/src/api-server/V1/v1Routes/v1-trashRoutes.ts index fa6b150..94f47fb 100644 --- a/src/api-server/V1/v1Routes/v1-trashRoutes.ts +++ b/src/api-server/V1/v1Routes/v1-trashRoutes.ts @@ -2,7 +2,7 @@ import express from "express"; import { tokenValidator } from "../../../shared/utils/token.ts"; import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; import { - DeleteTrash, + DeleteTrashData, GetTrashList, RestoreTrash, } from "../../V1/v1Controllers/trashController/v1trashController.ts"; @@ -22,11 +22,10 @@ v1TrashRoutes.patch( // authorizedRoles("Admin", "User"), RestoreTrash ); - v1TrashRoutes.patch( "/Trash/Delete", tokenValidator, // authorizedRoles("Admin", "User"), - DeleteTrash + DeleteTrashData ); export default v1TrashRoutes; diff --git a/src/shared/services/helpers/v1projecthelperFns.ts b/src/shared/services/helpers/v1projecthelperFns.ts index 9a773a6..186753b 100644 --- a/src/shared/services/helpers/v1projecthelperFns.ts +++ b/src/shared/services/helpers/v1projecthelperFns.ts @@ -22,6 +22,7 @@ export const existingUser = async (userId: string, organization: string) => { } const userData = await AuthModel(organization).findOne({ _id: userId, + isArchive: false, }); return userData; }; @@ -90,11 +91,11 @@ export const existingProjectById = async ( }; export const existingProjectByIdWithoutUser = async ( projectId: string, - organization: string, + organization: string ) => { const projectData = await projectModel(organization).findOne({ _id: projectId, isArchive: false, }); return projectData; -}; \ No newline at end of file +}; diff --git a/src/shared/services/trash/trashService.ts b/src/shared/services/trash/trashService.ts index 99cb305..0a9b58d 100644 --- a/src/shared/services/trash/trashService.ts +++ b/src/shared/services/trash/trashService.ts @@ -2,18 +2,14 @@ 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, userId } = data; - const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; + const { organization } = data; const TrashLists = await projectModel(organization).find({ isArchive: true, isDeleted: false, @@ -51,9 +47,7 @@ export const TrashDatas = async (data: IOrg) => { }; export const RestoreTrashData = async (data: IRestore) => { try { - const { projectId, organization, userId } = data; - const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; + const { projectId, organization } = data; const findProject = await projectModel(organization).findOne({ _id: projectId, isArchive: true, @@ -70,25 +64,4 @@ 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/v1Project/v1projectservice.ts b/src/shared/services/v1Project/v1projectservice.ts index b5c3dce..5266fc6 100644 --- a/src/shared/services/v1Project/v1projectservice.ts +++ b/src/shared/services/v1Project/v1projectservice.ts @@ -16,6 +16,14 @@ interface CreateProjectInput { sharedUsers?: string[]; organization: string; } +interface IProjectDuplicate { + projectName: string; + projectUuid: string; + userId: string; // user ID + thumbnail?: string; + sharedUsers?: string[]; + organization: string; +} interface updateProjectInput { projectName: string; projectId: string; @@ -30,6 +38,11 @@ interface GetProjectsInterface { organization: string; role: string; } +interface ProjectDelInterface { + projectId: string; + userId: string; + organization: string; +} interface ProjectInterface { projectId: string; userId: string; @@ -44,6 +57,7 @@ export const createProject = async (data: CreateProjectInput) => { try { const { thumbnail, sharedUsers, projectUuid, userId, organization } = data; const userExisting = await existingUser(userId, organization); + console.log("userExisting: ", userExisting); if (!userExisting) { return { status: "user_not_found", @@ -115,16 +129,18 @@ export const GetAllProjects = async (data: GetProjectsInterface) => { } }; -export const DeleteProject = async (data: ProjectInterface) => { +export const DeleteProject = async (data: ProjectDelInterface) => { try { - const { projectId, organization, userId, role } = data; + const { projectId, organization, userId } = data; const ExistingUser = await existingUser(userId, organization); if (!ExistingUser) return { status: "User not found" }; + let filter = { _id: projectId, isArchive: false } as RoleFilter; // if (role === "User") { // filter.createdBy = userId; // } const existingProject = await projectModel(organization).findOne(filter); + console.log("existingProject: ", existingProject); if (!existingProject) return { status: "Project not found" }; const updateProject = await projectModel(organization).findOneAndUpdate( filter, @@ -162,6 +178,63 @@ export const updateProject = async (data: updateProjectInput) => { return { status: error }; } }; + +export const DuplicateProject = async (data: IProjectDuplicate) => { + try { + const { + thumbnail, + sharedUsers, + projectUuid, + userId, + organization, + projectName, + } = data; + const userExisting = await existingUser(userId, organization); + if (!userExisting) { + return { + status: "user_not_found", + }; + } + const projectExisting = await existingProject( + projectUuid, + organization, + userId + ); + + if (projectExisting) { + return { + status: "project_exists", + project: projectExisting, + }; + } + const project = await projectModel(organization).create({ + projectName: projectName, + projectUuid: projectUuid, + createdBy: userId, + thumbnail: thumbnail, + sharedUsers: sharedUsers || [], + isArchive: false, + }); + const versionData = await previousVersion(project._id, organization); + if (!versionData || versionData.length === 0) { + const newVersion = await versionModel(organization).create({ + projectId: project._id, + createdBy: userId, + version: 0.0, + }); + await projectModel(organization).findByIdAndUpdate( + { _id: project._id, isArchive: false }, + { total_versions: `v-${newVersion.version.toFixed(2)}` } + ); + } + return { + status: "Success", + project: project, + }; + } catch (error: unknown) { + return { status: error }; + } +}; const maxLength: number = 6; export const viewProject = async (data: ProjectInterface) => { try { @@ -193,8 +266,8 @@ export const viewProject = async (data: ProjectInterface) => { newArr.pop(); } } - await UsersDataModel(organization).updateOne( - { _id: userId }, + const datas = await UsersDataModel(organization).findOneAndUpdate( + { userId: userId, isArchive: false }, { recentlyViewed: newArr }, { new: true } ); diff --git a/src/shared/services/v1home/v1homeservice.ts b/src/shared/services/v1home/v1homeservice.ts index 4dab787..b4f1d4a 100644 --- a/src/shared/services/v1home/v1homeservice.ts +++ b/src/shared/services/v1home/v1homeservice.ts @@ -1,7 +1,6 @@ import projectModel from "../../V1Models/Project/project-model.ts"; -import userModel from "../../model/user-Model.ts"; import UsersDataModel from "../../V1Models/Auth/user.ts"; -import { existingUser } from "../helpers/ProjecthelperFn.ts"; +import { existingUser } from "../helpers/v1projecthelperFns.ts"; interface IRecentData { organization: string; @@ -29,7 +28,6 @@ export const RecentlyAdded = async (data: IRecentData) => { try { const { userId, organization, role } = data; const userExisting = await existingUser(userId, organization); - console.log('userExisting: ', userExisting); if (!userExisting) return { status: "User not found" }; const userRecentData = await UsersDataModel(organization) .findOne({ userId: userId, isArchive: false }) @@ -43,16 +41,19 @@ export const RecentlyAdded = async (data: IRecentData) => { // filter.createdBy = userId; // } const populatedProjects = userRecentData.recentlyViewed as IProject[]; + console.log("populatedProjects: ", populatedProjects); const RecentDatas = await Promise.all( populatedProjects.map(async (project) => { const projectExisting = await projectModel(organization) - .findOne(filter) + .findOne({ _id: project._id, isArchive: false }) .select("_id projectName createdBy thumbnail createdAt isViewed"); return projectExisting; }) ); + console.log("RecentDatas: ", RecentDatas); const filteredProjects = RecentDatas.filter(Boolean); + console.log("filteredProjects: ", filteredProjects); return { status: "Success", data: filteredProjects }; } catch (error) { return { status: error }; diff --git a/src/shared/services/v1trash/v1trashservice.ts b/src/shared/services/v1trash/v1trashservice.ts index 8212569..08ee5d3 100644 --- a/src/shared/services/v1trash/v1trashservice.ts +++ b/src/shared/services/v1trash/v1trashservice.ts @@ -1,4 +1,5 @@ import projectModel from "../../V1Models/Project/project-model.ts"; +import { existingUser } from "../helpers/v1projecthelperFns.ts"; interface IOrg { organization: string; role: string; @@ -21,6 +22,8 @@ export const TrashDatas = async (data: IOrg) => { // if (role === "User") { // filter.createdBy = userId; // } + const UserExists = await existingUser(userId, organization); + if (!UserExists) return { status: "User not found" }; const TrashLists = await projectModel(organization).find(filter); if (!TrashLists) return { staus: "Trash is Empty" }; const TrashDocs: any[] = []; @@ -56,6 +59,8 @@ export const TrashDatas = async (data: IOrg) => { export const RestoreTrashData = async (data: IRestore) => { try { const { projectId, organization, role, userId } = data; + const UserExists = await existingUser(userId, organization); + if (!UserExists) return { status: "User not found" }; let filter = { isArchive: true, _id: projectId } as RoleFilter; // if (role === "User") { // filter.createdBy = userId; @@ -73,3 +78,24 @@ 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, isDeleted: false }, + { isDeleted: true }, + { new: true } + ); + if (!DeleteTrashData) return { status: "Project Already Deleted" }; + return { status: "Trash Project Delete successfully" }; + } catch (error) { + return { status: error }; + } +}; diff --git a/src/shared/services/visualization/floatWidgetService.ts b/src/shared/services/visualization/floatWidgetService.ts index d3a6c2c..43cf79e 100644 --- a/src/shared/services/visualization/floatWidgetService.ts +++ b/src/shared/services/visualization/floatWidgetService.ts @@ -1,6 +1,9 @@ import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts"; import zoneModel from "../../V1Models/Builder/zoneModel.ts"; -import { existingUser } from "../helpers/v1projecthelperFns.ts"; +import { + existingProjectById, + existingUser, +} from "../helpers/v1projecthelperFns.ts"; interface IResult { status: string; @@ -75,6 +78,12 @@ export const AddFloat = async (data: IAddFloatData): Promise => { const { organization, widget, zoneId, index, 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 existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -163,6 +172,12 @@ export const DelFloat = async (data: IDelFloat): Promise => { const { organization, floatWidgetID, zoneId, 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 existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -210,6 +225,12 @@ export const DuplicateFloat = async ( const { organization, widget, zoneId, index, 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 existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -312,6 +333,12 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise => { const { organization, zoneId, 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 existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -361,6 +388,7 @@ export const SingleFloatWidget = async ( const { organization, floatWidgetID, userId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; + const widgetData = await floatWidgetModel(organization) .findOne({ floatWidgetID: floatWidgetID, diff --git a/src/shared/services/visualization/panelService.ts b/src/shared/services/visualization/panelService.ts index 98326ed..09bad2c 100644 --- a/src/shared/services/visualization/panelService.ts +++ b/src/shared/services/visualization/panelService.ts @@ -1,7 +1,10 @@ import panelModel from "../../V1Models/Vizualization/panelmodel.ts"; import zoneModel from "../../V1Models/Builder/zoneModel.ts"; import widgetModel from "../../V1Models/Vizualization/widgemodel.ts"; -import { existingUser } from "../helpers/v1projecthelperFns.ts"; +import { + existingProjectById, + existingUser, +} from "../helpers/v1projecthelperFns.ts"; interface IResult { status: string; data?: object; @@ -32,6 +35,12 @@ export const AddPanel = async (data: IAddPanel): Promise => { const { organization, zoneId, panelOrder, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; + const LivingProject = await existingProjectById( + projectId, + organization, + userId + ); + if (!LivingProject) return { status: "Project not found" }; const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -97,6 +106,12 @@ export const DelPanel = async (data: IPanel): Promise => { const { organization, zoneId, panelName, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; + const LivingProject = await existingProjectById( + projectId, + organization, + userId + ); + if (!LivingProject) return { status: "Project not found" }; const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -156,6 +171,12 @@ export const ClearPanel = async (data: IPanel): Promise => { const { organization, zoneId, panelName, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; + const LivingProject = await existingProjectById( + projectId, + organization, + userId + ); + if (!LivingProject) return { status: "Project not found" }; const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -219,6 +240,12 @@ export const LockedPanel = async (data: ILockedPanel): Promise => { const { organization, zoneId, lockedPanel, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; + const LivingProject = await existingProjectById( + projectId, + organization, + userId + ); + if (!LivingProject) return { status: "Project not found" }; const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -267,6 +294,8 @@ const getZoneAndPanelData = async ( projectId: string ) => { try { + + const existingZone = await zoneModel(organization) .findOne({ zoneId: zoneId, diff --git a/src/shared/services/visualization/templateService.ts b/src/shared/services/visualization/templateService.ts index 4b9a503..650e6ec 100644 --- a/src/shared/services/visualization/templateService.ts +++ b/src/shared/services/visualization/templateService.ts @@ -3,7 +3,10 @@ import panelModel from "../../V1Models/Vizualization/panelmodel.ts"; import zoneModel from "../../V1Models/Builder/zoneModel.ts"; import widgetModel from "../../V1Models/Vizualization/widgemodel.ts"; import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts"; -import { existingUser } from "../helpers/v1projecthelperFns.ts"; +import { + existingProjectById, + existingUser, +} from "../helpers/v1projecthelperFns.ts"; interface IResult { status: string; data?: object; @@ -45,6 +48,12 @@ export const AddTemplate = async (data: IAddTemplate): Promise => { const { organization, template, 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 existingTemplate = await templateModel(organization).findOne({ templateID: template.id, isArchive: false, @@ -96,6 +105,12 @@ export const AddTemplateToZone = async ( const { organization, templateID, projectId, zoneId, 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 existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -238,6 +253,12 @@ export const TemplateDelete = async (data: ITemplate): Promise => { const { templateID, projectId, userId, organization } = 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 existingTemplate = await templateModel(organization).findOne({ templateID: templateID, isArchive: false, @@ -275,6 +296,12 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise => { const { organization, userId, projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; + const LivingProject = await existingProjectById( + projectId, + organization, + userId + ); + if (!LivingProject) return { status: "Project not found" }; const templateDatas = await templateModel(organization) .find({ projectId: projectId, isArchive: false }) .select("-_id -__v -isArchive -createdAt -updatedAt"); diff --git a/src/shared/services/visualization/widget3dService.ts b/src/shared/services/visualization/widget3dService.ts index 9eb6385..8fd43e5 100644 --- a/src/shared/services/visualization/widget3dService.ts +++ b/src/shared/services/visualization/widget3dService.ts @@ -1,6 +1,9 @@ import zoneModel from "../../V1Models/Builder/zoneModel.ts"; import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts"; -import { existingUser } from "../helpers/v1projecthelperFns.ts"; +import { + existingProjectById, + existingUser, +} from "../helpers/v1projecthelperFns.ts"; interface IResult { status: string; data?: object; @@ -47,6 +50,12 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise => { 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, @@ -120,6 +129,13 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise => { 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, @@ -183,6 +199,12 @@ export const Delete3Dwidget = async ( const { organization, id, 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, @@ -238,6 +260,12 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise => { const { organization, 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,