From fd578df59f476fa10dc9fba8d07e4eba996d80a4 Mon Sep 17 00:00:00 2001 From: Nivetharamesh Date: Mon, 26 May 2025 15:08:22 +0530 Subject: [PATCH] api/v2 routing added for the userDatas --- .../authController/authControllers.ts | 2 + .../builderController/v1cameraController.ts | 115 ++++++++++++++++++ src/api-server/app.ts | 2 +- src/shared/services/builder/cameraService.ts | 14 +-- 4 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 src/api-server/V1/v1Controllers/builderController/v1cameraController.ts diff --git a/src/api-server/V1/v1Controllers/authController/authControllers.ts b/src/api-server/V1/v1Controllers/authController/authControllers.ts index 710b4d4..2a6bdb7 100644 --- a/src/api-server/V1/v1Controllers/authController/authControllers.ts +++ b/src/api-server/V1/v1Controllers/authController/authControllers.ts @@ -52,6 +52,7 @@ export const SignInController = async ( ): Promise => { try { const { Email, Password, fingerprint } = req.body; + console.log("req.body: ", req.body); if (!fingerprint || !Email || !Password) { res.status(400).json({ message: "All fields are required", @@ -74,6 +75,7 @@ export const SignInController = async ( case "Already LoggedIn on another browser....Please logout!!!": res.status(403).json({ message: "Already LoggedIn on another browser....Please logout!!!", + ForceLogoutData: result.data, }); break; diff --git a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts new file mode 100644 index 0000000..272938b --- /dev/null +++ b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts @@ -0,0 +1,115 @@ +import { Request, Response } from "express"; + +import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; +import { + GetCamers, + SetCamera, +} from "../../../../shared/services/builder/cameraService.ts"; + +export const SetNewCamera = 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 + ) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const data = { + position, + target, + rotation, + projectId, + versionId, + organization, + role, + userId, + }; + const result = await SetCamera(data); + + switch (result.status) { + case "Project not found": + res.status(404).json({ + message: "Project not found", + TrashDatas: [], + }); + break; + + case "Update Success": + res.status(200).json({ + TrashDatas: result.data, + }); + break; + case "Success": + res.status(200).json({ + TrashDatas: 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 CameraList = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { organization, role, userId } = req.user || {}; + if (!organization || !role || !userId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await GetCamers({ + organization, + role, + userId, + }); + + switch (result.status) { + case "Project not found": + res.status(404).json({ + message: "Project not found", + TrashDatas: [], + }); + break; + case "Success": + res.status(200).json({ + TrashDatas: 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/app.ts b/src/api-server/app.ts index 99ae949..eeaa666 100644 --- a/src/api-server/app.ts +++ b/src/api-server/app.ts @@ -94,7 +94,7 @@ app.use("/api/v1", trashRouter); app.use("/api/v1", homePageRouter); //New versions--based on the token and role based -app.use("/api", Authrouter); +app.use("/api/v2", Authrouter); app.use("/api/v2", v1projectRouter); app.use("/api/v2", v1TrashRoutes); app.use("/api/v2", v1homeRoutes); diff --git a/src/shared/services/builder/cameraService.ts b/src/shared/services/builder/cameraService.ts index 94c1d7c..4256e0b 100644 --- a/src/shared/services/builder/cameraService.ts +++ b/src/shared/services/builder/cameraService.ts @@ -1,11 +1,9 @@ -import projectModel from "../../model/project/project-model.ts"; -import userModel from "../../model/user-Model.ts"; -import versionModel from "../../model/version/versionModel.ts"; import UsersDataModel from "../../V1Models/Auth/user.ts"; import cameraModel from "../../V1Models/Builder/cameraModel.ts"; -import { existingProjectById } from "../helpers/ProjecthelperFn.ts"; +import { existingProjectById } from "../helpers/v1projecthelperFns.ts"; interface IcameraData { userId: string; + role: string; position: Object; target: Object; rotation: Object; @@ -16,6 +14,7 @@ interface IcameraData { interface IgetCameras { organization: string; userId?: string; + role: string; } export const SetCamera = async ( data: IcameraData @@ -23,6 +22,7 @@ export const SetCamera = async ( try { const { userId, + role, position, target, rotation, @@ -65,7 +65,7 @@ export const SetCamera = async ( }); return { - status: "Creation Success", + status: "Success", data: newCamera, }; } @@ -84,13 +84,13 @@ export const SetCamera = async ( export const GetCamers = async ( data: IgetCameras ): Promise<{ status: string; data?: Object }> => { - const { userId, organization } = data; + const { userId, organization, role } = data; try { const findCamera = await cameraModel(organization).findOne({ userId: userId, }); if (!findCamera) { - return { status: "user not found" }; + return { status: "Camera not found" }; } else { return { status: "Success", data: findCamera }; }