Role nd token Based Routing completed for Project,trash,home which is in Controller. Token, Auth Purpose,Rolebased middlewares created. Auth API,Project token Based API, Home Token Based API, Trash Token Based API In v1 AuthRoutes

This commit is contained in:
2025-05-19 16:06:09 +05:30
parent 2aa8c479fa
commit ac8de5d33d
28 changed files with 1748 additions and 224 deletions

View File

@@ -0,0 +1,155 @@
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";
interface IcameraData {
userId: string;
position: Object;
target: Object;
rotation: Object;
organization: string;
projectId: string;
versionId: string;
}
interface IgetCameras {
organization: string;
userId?: string;
}
export const SetCamera = async (
data: IcameraData
): Promise<{ status: string; data?: Object }> => {
try {
const {
userId,
position,
target,
rotation,
organization,
projectId,
versionId,
} = data;
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingCamera = await cameraModel(organization).findOne({
userId: userId,
});
if (existingCamera) {
const updateCamera = await cameraModel(organization).findOneAndUpdate(
{
userId: userId,
projectId: projectId,
versionId: versionId,
isArchive: false,
},
{ position: position, target: target, rotation: rotation },
{ new: true }
);
return {
status: "Update Success",
data: updateCamera,
};
} else {
const newCamera = await cameraModel(organization).create({
userId,
projectId,
versionId,
position,
target,
rotation,
});
return {
status: "Creation Success",
data: newCamera,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const GetCamers = async (
data: IgetCameras
): Promise<{ status: string; data?: Object }> => {
const { userId, organization } = data;
try {
const findCamera = await cameraModel(organization).findOne({
userId: userId,
});
if (!findCamera) {
return { status: "user not found" };
} else {
return { status: "Success", data: findCamera };
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const onlineActiveDatas = async (
data: IgetCameras
): Promise<{ status: string; data?: Object }> => {
const { organization } = data;
try {
const findactiveUsers = await UsersDataModel(organization).find({
activeStatus: "online",
});
const cameraDataPromises = findactiveUsers.map(async (activeUser: any) => {
const cameraData = await cameraModel(organization)
.findOne({ userId: activeUser._id })
.select("position target rotation -_id");
if (cameraData) {
return {
position: cameraData.position,
target: cameraData.target,
rotation: cameraData.rotation,
userData: {
_id: activeUser._id,
userName: activeUser.userName,
email: activeUser.email,
activeStatus: activeUser.activeStatus,
},
};
}
return null;
});
const cameraDatas = (await Promise.all(cameraDataPromises)).filter(
(singledata: any) => singledata !== null
);
return { status: "Success", data: cameraDatas };
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};