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

@@ -52,6 +52,7 @@ export const SignInController = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { Email, Password, fingerprint } = req.body; const { Email, Password, fingerprint } = req.body;
console.log("req.body: ", req.body);
if (!fingerprint || !Email || !Password) { if (!fingerprint || !Email || !Password) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: "All fields are required",
@@ -74,6 +75,7 @@ export const SignInController = async (
case "Already LoggedIn on another browser....Please logout!!!": case "Already LoggedIn on another browser....Please logout!!!":
res.status(403).json({ res.status(403).json({
message: "Already LoggedIn on another browser....Please logout!!!", message: "Already LoggedIn on another browser....Please logout!!!",
ForceLogoutData: result.data,
}); });
break; break;

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",
});
}
};

View File

@@ -94,7 +94,7 @@ app.use("/api/v1", trashRouter);
app.use("/api/v1", homePageRouter); app.use("/api/v1", homePageRouter);
//New versions--based on the token and role based //New versions--based on the token and role based
app.use("/api", Authrouter); app.use("/api/v2", Authrouter);
app.use("/api/v2", v1projectRouter); app.use("/api/v2", v1projectRouter);
app.use("/api/v2", v1TrashRoutes); app.use("/api/v2", v1TrashRoutes);
app.use("/api/v2", v1homeRoutes); app.use("/api/v2", v1homeRoutes);

View File

@@ -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 UsersDataModel from "../../V1Models/Auth/user.ts";
import cameraModel from "../../V1Models/Builder/cameraModel.ts"; import cameraModel from "../../V1Models/Builder/cameraModel.ts";
import { existingProjectById } from "../helpers/ProjecthelperFn.ts"; import { existingProjectById } from "../helpers/v1projecthelperFns.ts";
interface IcameraData { interface IcameraData {
userId: string; userId: string;
role: string;
position: Object; position: Object;
target: Object; target: Object;
rotation: Object; rotation: Object;
@@ -16,6 +14,7 @@ interface IcameraData {
interface IgetCameras { interface IgetCameras {
organization: string; organization: string;
userId?: string; userId?: string;
role: string;
} }
export const SetCamera = async ( export const SetCamera = async (
data: IcameraData data: IcameraData
@@ -23,6 +22,7 @@ export const SetCamera = async (
try { try {
const { const {
userId, userId,
role,
position, position,
target, target,
rotation, rotation,
@@ -65,7 +65,7 @@ export const SetCamera = async (
}); });
return { return {
status: "Creation Success", status: "Success",
data: newCamera, data: newCamera,
}; };
} }
@@ -84,13 +84,13 @@ export const SetCamera = async (
export const GetCamers = async ( export const GetCamers = async (
data: IgetCameras data: IgetCameras
): Promise<{ status: string; data?: Object }> => { ): Promise<{ status: string; data?: Object }> => {
const { userId, organization } = data; const { userId, organization, role } = data;
try { try {
const findCamera = await cameraModel(organization).findOne({ const findCamera = await cameraModel(organization).findOne({
userId: userId, userId: userId,
}); });
if (!findCamera) { if (!findCamera) {
return { status: "user not found" }; return { status: "Camera not found" };
} else { } else {
return { status: "Success", data: findCamera }; return { status: "Success", data: findCamera };
} }