api/v2 routing added for the userDatas

This commit is contained in:
2025-05-26 15:08:22 +05:30
parent 089c6af1b6
commit fd578df59f
4 changed files with 125 additions and 8 deletions

View File

@@ -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<void> => {
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<void> => {
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",
});
}
};