Controller and routing for the Vizualtion and builder

This commit is contained in:
2025-05-29 15:34:12 +05:30
parent bea6044b25
commit c38a698692
34 changed files with 2523 additions and 926 deletions

View File

@@ -1,86 +1,119 @@
import environmentModel from "../../V1Models/Environment/environments-Model.ts";
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface EnvironmentInput {
roofVisibility: boolean;
wallVisibility: boolean;
shadowVisibility: boolean;
renderDistance: number;
limitDistance: boolean;
organization: string;
projectId: string;
userId: string;
roofVisibility: boolean;
wallVisibility: boolean;
shadowVisibility: boolean;
renderDistance: number;
limitDistance: boolean;
organization: string;
projectId: string;
userId: string;
}
interface GetEnvironmentInput {
organization: string;
projectId: string;
userId: string;
}
export const setEnvironment = async (
data: EnvironmentInput
data: EnvironmentInput
): Promise<{ status: string; data?: Object }> => {
try {
const { roofVisibility, wallVisibility, shadowVisibility, organization, 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 findvalue = await environmentModel(organization).findOne({ userId: userId })
if (findvalue) {
const updatevalue = await environmentModel(organization).findOneAndUpdate(
{ userId: userId, projectId: projectId }, { roofVisibility: roofVisibility, wallVisibility: wallVisibility, shadowVisibility: shadowVisibility }, { new: true });
// return { success: true, message: 'evironments updated', data: updatevalue,organization:organization }
return { status: 'evironments updated', data: updatevalue }
} else {
const newValue = await environmentModel(organization).create({ userId, projectId, roofVisibility, wallVisibility, shadowVisibility });
// return { success: true, message: 'evironments created', data: newValue,organization:organization }
return { status: 'Success', data: newValue }
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
try {
const {
roofVisibility,
wallVisibility,
renderDistance,
limitDistance,
shadowVisibility,
organization,
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 findvalue = await environmentModel(organization).findOne({
userId: userId,
isArchive: false,
});
if (findvalue) {
const updatevalue = await environmentModel(organization).findOneAndUpdate(
{ userId: userId, projectId: projectId, isArchive: false },
{
roofVisibility: roofVisibility,
wallVisibility: wallVisibility,
shadowVisibility: shadowVisibility,
renderDistance: renderDistance,
limitDistance: limitDistance,
},
{ new: true }
);
return { status: "environments updated", data: updatevalue };
} else {
const newValue = await environmentModel(organization).create({
userId,
projectId,
roofVisibility,
wallVisibility,
shadowVisibility,
});
return { status: "Success", data: newValue };
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const getEnvironment = async (
data: EnvironmentInput
data: GetEnvironmentInput
): Promise<{ status: string; data?: Object }> => {
try {
const { organization, 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" };
try {
const { organization, 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 findValue = await environmentModel(organization).findOne({
userId: userId, projectId: projectId
});
if (!findValue) {
// res.status(200).json("user not found");
return { status: 'evironments user not found' }
} else {
// res.status(201).json(findValue);
return { status: 'Success', data: findValue }
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
const findValue = await environmentModel(organization).findOne({
userId: userId,
projectId: projectId,
isArchive: false,
});
if (!findValue) {
return { status: "Environment Not found for the User" };
} else {
return { status: "Success", data: findValue };
}
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};

View File

@@ -1,473 +1,539 @@
import { Mixed } from "mongoose";
import assetModel from "../../V1Models/Builder/assetModel.ts";
import EventsDataModel from "../../V1Models/Simulation/eventsDataModel.ts";
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface setAssetInput {
modelUuid: string;
modelName: string;
position: []; // user ID
rotation: object;
eventData: Mixed;
modelfileID: string;
isLocked: boolean;
isVisible: boolean;
organization: string;
projectId: string;
userId: string;
modelUuid: string;
modelName: string;
position: []; // user ID
rotation: object;
eventData: Mixed;
modelfileID: string;
isLocked: boolean;
isVisible: boolean;
organization: string;
projectId: string;
userId: string;
}
interface AssetUpdate {
modelUuid: string;
modelName: string;
position: []; // user ID
rotation: object;
isLocked: boolean;
isVisible: boolean;
organization: string;
projectId: string;
userId: string;
}
interface DelAssetInput {
modelUuid: string;
modelName: string;
organization: string;
projectId: string;
userId: string;
}
interface GetAssetInput {
organization: string;
projectId: string;
userId: string;
}
interface ReplaceEventInput {
organization: string;
projectId: string;
userId: string;
eventData: Mixed;
modelUuid: string;
}
export const setAssetModel = async (
data: setAssetInput
data: setAssetInput
): Promise<{ status: string; data?: Object }> => {
try {
const { modelUuid,
modelName,
position,
rotation,
eventData,
modelfileID,
isLocked,
isVisible,
organization, 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 findvalue = await assetModel(organization).findOne({
modelUuid: modelUuid,
projectId: projectId,
userId: userId,
isArchive: false,
});
if (findvalue) {
const updatevalue = await assetModel(organization).findOneAndUpdate(
{ modelUuid: modelUuid, projectId: projectId, userId: userId, isArchive: false },
{
modelName: modelName,
position: position,
rotation: rotation,
isVisible: isVisible,
isLocked: isLocked,
eventData: eventData,
},
{ new: true }
);
// return {
// success: true,
// message: "Model updated successfully",
// data: updatevalue,
// organization: organization,
// };
return {
status: "Updated successfully",
data: updatevalue,
};
try {
const {
modelUuid,
modelName,
position,
rotation,
eventData,
modelfileID,
isLocked,
isVisible,
organization,
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 findvalue = await assetModel(organization).findOne({
modelUuid: modelUuid,
projectId: projectId,
userId: userId,
isArchive: false,
});
if (findvalue) {
const updatevalue = await assetModel(organization).findOneAndUpdate(
{
modelUuid: modelUuid,
projectId: projectId,
userId: userId,
isArchive: false,
},
{
modelName: modelName,
position: position,
rotation: rotation,
isVisible: isVisible,
isLocked: isLocked,
eventData: eventData,
},
{ new: true }
);
// return {
// success: true,
// message: "Model updated successfully",
// data: updatevalue,
// organization: organization,
// };
return {
status: "Updated successfully",
data: updatevalue,
};
} else {
let assetData: any = {
projectId,
userId,
modelUuid,
modelName,
position,
modelfileID,
rotation,
isLocked,
isVisible,
};
// if (eventData) {
// if (eventData?.type === "Conveyor") {
// assetData.eventData = {
// type: eventData.type,
// // point:undefined,
// points: eventData.points,
// };
// } else {
// assetData.eventData = {
// type: eventData.type,
// point: eventData.point,
// // points: undefined
// };
// }
// }
if (eventData) {
const typedEventData = eventData as unknown as {
type: string;
point?: any;
points?: any[];
};
if (typedEventData.type === "Conveyor") {
assetData.eventData = {
type: typedEventData.type,
points: typedEventData.points,
};
} else {
let assetData: any = {
projectId,
userId,
modelUuid,
modelName,
position,
modelfileID,
rotation,
isLocked,
isVisible,
};
// if (eventData) {
// if (eventData?.type === "Conveyor") {
// assetData.eventData = {
// type: eventData.type,
// // point:undefined,
// points: eventData.points,
// };
// } else {
// assetData.eventData = {
// type: eventData.type,
// point: eventData.point,
// // points: undefined
// };
// }
// }
if (eventData) {
const typedEventData = eventData as unknown as { type: string; point?: any; points?: any[] };
if (typedEventData.type === "Conveyor") {
assetData.eventData = {
type: typedEventData.type,
points: typedEventData.points,
};
} else {
assetData.eventData = {
type: typedEventData.type,
point: typedEventData.point,
};
}
}
if (eventData) {
const typedEventData = eventData as unknown as { type: string; point?: any; points?: any[] };
if (typedEventData.type === "Conveyor") {
assetData.eventData = {
type: typedEventData.type,
points: typedEventData.points,
};
} else {
assetData.eventData = {
type: typedEventData.type,
point: typedEventData.point,
};
}
}
const assetDoc = await assetModel(organization).create(assetData);
await assetDoc.save();
let assetDatas;
const typedEventData = eventData as unknown as { type: string };
if (typedEventData && typedEventData.type === "Conveyor") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: eventData,
};
} else if (eventData && assetDoc.type === "Vehicle") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else if (eventData && assetDoc.type === "ArmBot") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else if (eventData && assetDoc.type === "StaticMachine") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
};
}
// return {
// success: true,
// message: "Model created successfully",
// data: assetDatas,
// organization: organization,
// };
return {
status: "Success",
data: assetDatas,
};
assetData.eventData = {
type: typedEventData.type,
point: typedEventData.point,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
}
if (eventData) {
const typedEventData = eventData as unknown as {
type: string;
point?: any;
points?: any[];
};
if (typedEventData.type === "Conveyor") {
assetData.eventData = {
type: typedEventData.type,
points: typedEventData.points,
};
} else {
return {
status: "An unexpected error occurred",
};
assetData.eventData = {
type: typedEventData.type,
point: typedEventData.point,
};
}
}
const assetDoc = await assetModel(organization).create(assetData);
await assetDoc.save();
let assetDatas;
const typedEventData = eventData as unknown as { type: string };
if (typedEventData && typedEventData.type === "Conveyor") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: eventData,
};
} else if (eventData && assetDoc.type === "Vehicle") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else if (eventData && assetDoc.type === "ArmBot") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else if (eventData && assetDoc.type === "StaticMachine") {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else {
assetDatas = {
projectId: assetDoc.projectId,
userId: assetDoc.userId,
modelUuid: assetDoc.modelUuid,
modelName: assetDoc.modelName,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
};
}
// return {
// success: true,
// message: "Model created successfully",
// data: assetDatas,
// organization: organization,
// };
return {
status: "Success",
data: assetDatas,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const deleteAssetModel = async (
data: setAssetInput
data: DelAssetInput
): Promise<{ status: string; data?: Object }> => {
try {
const { modelUuid, modelName, organization, 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 asset = await assetModel(organization).findOne({
modelUuid,
modelName,
projectId,
isArchive: false,
});
if (!asset) {
return {
status: "model not found",
};
}
const archivedAsset = await assetModel(organization).findOneAndUpdate(
{ modelUuid, modelName, projectId },
{ $set: { isArchive: true } },
{ new: true }
);
if (!archivedAsset) {
// return {
// success: false,
// status: "Failed to archive asset",
// organization: organization,
// };
}
const updatedEvents = await EventsDataModel(organization).updateMany(
{ modelUuid, productId: projectId },
{ $set: { isArchive: true } }
);
// return {
// success: true,
// message: "Model deleted successfully",
// data: archivedAsset,
// organization: organization,
// };
return {
status: "Model deleted successfully",
data: archivedAsset,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
try {
const { modelUuid, modelName, organization, 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 asset = await assetModel(organization).findOne({
modelUuid,
modelName,
projectId,
isArchive: false,
});
if (!asset) {
return {
status: "model not found",
};
}
const archivedAsset = await assetModel(organization).findOneAndUpdate(
{ modelUuid, modelName, projectId },
{ $set: { isArchive: true } },
{ new: true }
);
if (!archivedAsset) {
// return {
// success: false,
// status: "Failed to archive asset",
// organization: organization,
// };
return {
status: "Failed to archive asset",
};
}
const updatedEvents = await EventsDataModel(organization).updateMany(
{ modelUuid, productId: projectId },
{ $set: { isArchive: true } }
);
// return {
// success: true,
// message: "Model deleted successfully",
// data: archivedAsset,
// organization: organization,
// };
return {
status: "Success",
data: archivedAsset,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const replaceEventDatas = async (
data: setAssetInput
data: ReplaceEventInput
): Promise<{ status: string; data?: Object }> => {
try {
const { modelUuid, organization, eventData, 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 existingModel = await assetModel(organization).findOne({
modelUuid: modelUuid, projectId: projectId,
isArchive: false,
});
if (!existingModel) {
return { status: "Model not for this UUID" }
// return {
// success: false,
// message: "Model not for this UUID",
// organization: organization,
// };
}
else {
const typedEventData = eventData as unknown as {
speed: number; points?: any[];
type?: string;
};
let speed;
try {
const { modelUuid, organization, eventData, 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 existingModel = await assetModel(organization).findOne({
modelUuid: modelUuid,
projectId: projectId,
isArchive: false,
});
if (!existingModel) {
return { status: "Model not for this UUID" };
// return {
// success: false,
// message: "Model not for this UUID",
// organization: organization,
// };
} else {
const typedEventData = eventData as unknown as {
speed: number;
points?: any[];
type?: string;
};
let speed;
if (existingModel.type === "Conveyor") {
speed = typedEventData?.speed;
}
;
const updatedModel = await assetModel(organization).findOneAndUpdate(
{ modelUuid, projectId, isArchive: false },
{
points: typedEventData?.points,
// speed: speed,
type: typedEventData?.type || existingModel?.type,
},
{ new: true }
);
if (existingModel.type === "Conveyor") {
speed = typedEventData?.speed;
}
const updatedModel = await assetModel(organization).findOneAndUpdate(
{ modelUuid, projectId, isArchive: false },
{
points: typedEventData?.points,
// speed: speed,
type: typedEventData?.type || existingModel?.type,
},
{ new: true }
);
// if (updatedModel)
// // return {
// // success: true,
// // message: "Data updated successfully",
// // data: updatedModel,
// // organization: organization,
// // };
// return {
// status: "Success",
// data: updatedModel,
// };
return {
status: "Success",
data: updatedModel,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
// if (updatedModel)
// // return {
// // success: true,
// // message: "Data updated successfully",
// // data: updatedModel,
// // organization: organization,
// // };
// return {
// status: "Success",
// data: updatedModel,
// };
return {
status: "Success",
data: updatedModel,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const updateAssetPositionRotation = async (
data: setAssetInput
data: AssetUpdate
): Promise<{ status: string; data?: Object }> => {
try {
const { modelUuid, modelName, position, rotation, isLocked, isVisible, organization, 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 existingAsset = await assetModel(organization).findOne({
modelUuid: modelUuid, projectId: projectId,
isArchive: false,
});
if (!existingAsset) {
return { status: "Asset not found" }
// return res.send("Asset not found");
}
const updateAsset = await assetModel(organization).updateMany(
{ modelUuid: modelUuid, projectId: projectId, modelName: modelName, isArchive: false },
{
position: position,
rotation: rotation,
isVisible: isVisible,
isLocked: isLocked,
}
);
// if (updateAsset)
return {
status: "Success",
data: updateAsset,
};
// return res.status(200).json({ message: "Asset updated successfully" });
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
try {
const {
modelUuid,
modelName,
position,
rotation,
isLocked,
isVisible,
organization,
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 existingAsset = await assetModel(organization).findOne({
modelUuid: modelUuid,
projectId: projectId,
isArchive: false,
});
if (!existingAsset) {
return { status: "Asset not found" };
// return res.send("Asset not found");
}
const updateAsset = await assetModel(organization).updateMany(
{
modelUuid: modelUuid,
projectId: projectId,
modelName: modelName,
isArchive: false,
},
{
position: position,
rotation: rotation,
isVisible: isVisible,
isLocked: isLocked,
}
);
// if (updateAsset)
return {
status: "Success",
data: updateAsset,
};
// return res.status(200).json({ message: "Asset updated successfully" });
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const getFloorItems = async (
data: setAssetInput
data: GetAssetInput
): Promise<{ status: string; data?: Object }> => {
try {
const { organization, 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 findValues = await assetModel(organization)
.find({ isArchive: false })
.select("-_id -isArchive");
try {
const { organization, 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 findValues = await assetModel(organization)
.find({ isArchive: false })
.select("-_id -isArchive");
if (!findValues || findValues.length === 0) {
return { status: "floorItems not found" }
// return res.status(200).json({ message: "floorItems not found" });
}
const response = findValues.map((item) => {
const responseItem: any = {
projectId: item.productId,
modelUuid: item.modelUuid,
modelName: item.modelName,
position: item.position,
rotation: item.rotation,
modelfileID: item.modelfileID,
isLocked: item.isLocked,
isVisible: item.isVisible,
eventData: item.eventData,
};
return responseItem;
});
// return res.status(200).json(response);
return {
status: "Success",
data: response,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
if (!findValues || findValues.length === 0) {
return { status: "floorItems not found" };
// return res.status(200).json({ message: "floorItems not found" });
}
};
const response = findValues.map((item) => {
const responseItem: any = {
projectId: item.productId,
modelUuid: item.modelUuid,
modelName: item.modelName,
position: item.position,
rotation: item.rotation,
modelfileID: item.modelfileID,
isLocked: item.isLocked,
isVisible: item.isVisible,
eventData: item.eventData,
};
return responseItem;
});
// return res.status(200).json(response);
return {
status: "Success",
data: response,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};

View File

@@ -14,6 +14,11 @@ interface IcameraData {
versionId: string;
}
interface IgetCameras {
organization: string;
projectId: string;
userId: string;
}
interface IOnline {
organization: string;
userId: string;
}
@@ -40,6 +45,7 @@ export const SetCamera = async (
if (!LivingProject) return { status: "Project not found" };
const existingCamera = await cameraModel(organization).findOne({
userId: userId,
isArchive: false,
});
if (existingCamera) {
const updateCamera = await cameraModel(organization).findOneAndUpdate(
@@ -86,12 +92,14 @@ export const SetCamera = async (
export const GetCamers = async (
data: IgetCameras
): Promise<{ status: string; data?: Object }> => {
const { userId, organization } = data;
const { userId, organization, projectId } = data;
try {
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findCamera = await cameraModel(organization).findOne({
userId: userId,
projectId: projectId,
isArchive: false,
});
if (!findCamera) {
return { status: "Camera not found" };
@@ -111,7 +119,7 @@ export const GetCamers = async (
}
};
export const onlineActiveDatas = async (
data: IgetCameras
data: IOnline
): Promise<{ status: string; data?: Object }> => {
const { organization, userId } = data;
try {
@@ -119,11 +127,12 @@ export const onlineActiveDatas = async (
if (!UserExists) return { status: "User not found" };
const findactiveUsers = await UsersDataModel(organization).find({
activeStatus: "online",
isArchive: false,
});
const cameraDataPromises = findactiveUsers.map(async (activeUser: any) => {
const cameraData = await cameraModel(organization)
.findOne({ userId: activeUser._id })
.findOne({ userId: activeUser._id, isArchive: false })
.select("position target rotation -_id");
if (cameraData) {
@@ -143,7 +152,7 @@ export const onlineActiveDatas = async (
});
const cameraDatas = (await Promise.all(cameraDataPromises)).filter(
(singledata: any) => singledata !== null
(singledata: unknown) => singledata !== null
);
return { status: "Success", data: cameraDatas };

View File

@@ -8,7 +8,11 @@ interface ILineItems {
projectId: string;
userId: string;
}
interface ILineGet {
organization: string;
projectId: string;
userId: string;
}
interface ILineUpdate {
organization: string;
uuid: number;
@@ -67,19 +71,14 @@ export const UpdateLineItems = async (
const { organization, projectId, uuid, position, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
await lineModel(organization).updateMany(
const updateResult = await lineModel(organization).updateMany(
{ "line.uuid": uuid, projectId: projectId },
{ $set: { "line.$.position": position } }
);
// return {
// success: true,
// status: "line updated",
// data: { uuid: uuid, position: position },
// organization: organization,
// };
return {
status: "Success",
data: { uuid: uuid, position: position },
data: updateResult,
};
} catch (error: unknown) {
if (error instanceof Error) {
@@ -103,9 +102,9 @@ export const DeleteLineItems = async (
const inputUuids = line.map((item: any) => item.uuid);
const findValue = await lineModel(organization).findOneAndDelete(
{ projectId: projectId },
{ projectId: projectId, isArchive: false },
{
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
"line.uuid": { $all: inputUuids },
}
);
@@ -113,22 +112,11 @@ export const DeleteLineItems = async (
return {
status: "line not found",
};
// return {
// success: false,
// message: "line not found",
// organization: organization,
// };
} else {
return {
status: "Success",
data: findValue,
};
// return {
// success: true,
// message: "line deleted",
// data: findValue,
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {
@@ -152,11 +140,11 @@ export const DeleteLayer = async (
const findValue = await lineModel(organization).find({
layer: layer,
projectId: projectId,
isArchive: false,
});
if (!findValue) {
return { status: "layer not found" };
// return { success: false, message: "layer not found" };
} else {
await lineModel(organization).deleteMany(
{ projectId: projectId },
@@ -171,12 +159,6 @@ export const DeleteLayer = async (
status: "Success",
data: updateResult,
};
// return {
// success: true,
// message: "layer deleted",
// data: layer,
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {
@@ -191,6 +173,34 @@ export const DeleteLayer = async (
}
};
export const GetLinesService = async (
data: ILineGet
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await lineModel(organization).find({
projectId: projectId,
isArchive: false,
});
if (!findValue) {
return { status: "user not found" };
} else {
return { status: "Success", data: findValue };
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const DeleteLinePoints = async (
data: ILinePointsDelete
): Promise<{ status: string; data?: object }> => {
@@ -199,7 +209,7 @@ export const DeleteLinePoints = async (
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await lineModel(organization).deleteMany(
{ projectId: projectId },
{ projectId: projectId, isArchive: false },
{
"line.uuid": uuid,
}
@@ -207,19 +217,8 @@ export const DeleteLinePoints = async (
if (!findValue) {
return { status: "Line not found" };
// return {
// success: false,
// message: "line not found",
// organization: organization,
// };
} else {
return { status: "Success" };
// return {
// success: true,
// message: "point deleted",
// data: uuid,
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {

View File

@@ -49,11 +49,12 @@ export class WallItems {
if (!UserExists) return { status: "User not found" };
const findvalue = await wallItemModel(organization).findOne({
modelUuid: modelUuid,
isArchive: false,
});
if (findvalue) {
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
{ modelUuid: modelUuid, projectId: projectId },
{ modelUuid: modelUuid, projectId: projectId, isArchive: false },
{
modelName,
position,
@@ -63,13 +64,12 @@ export class WallItems {
quaternion,
scale,
},
{ new: true } // Return the updated document
{ new: true }
);
return {
status: "Updated successfully",
data: updatevalue,
};
// res.status(201).json(updatevalue);
} else {
const newValue = await wallItemModel(organization).create({
modelUuid,
@@ -86,7 +86,6 @@ export class WallItems {
status: "wall Item created successfully",
data: newValue,
};
// res.status(201).json(newValue);
}
} catch (error: unknown) {
if (error instanceof Error) {
@@ -107,6 +106,7 @@ export class WallItems {
if (!UserExists) return { status: "User not found" };
const findValue = await wallItemModel(organization).find({
projectId: projectId,
isArchive: false,
});
if (!findValue) {
return {
@@ -139,6 +139,7 @@ export class WallItems {
modelUuid: modelUuid,
modelName: modelName,
projectId: projectId,
isArchive: false,
});
if (!findValue) {
return {

View File

@@ -24,12 +24,18 @@ interface IZone {
zoneId: string;
userId: string;
}
interface IVizZone {
organization: string;
projectId: string;
userId: string;
}
interface IResult {
status: string;
data?: object;
}
interface IGetZones {
organization: string;
projectId: string;
userId: string;
}
@@ -51,7 +57,7 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
if (findZoneId) {
const updateZone = await zoneModel(organization)
.findOneAndUpdate(
{ zoneId: zoneId, projectId: projectId },
{ zoneId: zoneId, projectId: projectId, isArchive: false },
{
points: points,
viewPortposition: viewPortposition,
@@ -60,7 +66,6 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
{ new: true }
)
.select("-_id -__v");
// return { success: true, message: 'zone updated', data: updateZone, organization: organization }
return { status: "zone updated", data: updateZone };
} else {
const zoneCreate = await zoneModel(organization).create({
@@ -76,7 +81,6 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
const createdZone = await zoneModel(organization)
.findById(zoneCreate._id)
.select("-_id -__v");
// return { success: true, status: 'zone created', data: createdZone, organization: organization }
return { status: "Success", data: createdZone };
}
} catch (error: unknown) {
@@ -97,6 +101,7 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
const findZoneId = await zoneModel(organization).findOne({
zoneId: zoneId,
projectId: projectId,
isArchive: false,
});
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
@@ -110,7 +115,10 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
})
.select("-_id -__v");
if (deleteZone) {
const panels = await panelModel(organization).find({ zoneId });
const panels = await panelModel(organization).find({
zoneId,
isArchive: false,
});
const allWidgetIds = panels.reduce((ids: string[], panel: any) => {
return ids.concat(panel.widgets || []);
@@ -122,32 +130,26 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
);
await panelModel(organization).updateMany(
{ zoneId },
{ zoneId, isArchive: false },
{ $set: { isArchive: true } }
);
await Promise.all([
widget3dModel(organization).updateMany(
{ zoneId },
{ zoneId, isArchive: false },
{ $set: { isArchive: true } }
),
templateModel(organization).updateMany(
{ zoneId },
{ zoneId, isArchive: false },
{ $set: { isArchive: true } }
),
floatWidgetModel(organization).updateMany(
{ zoneId },
{ zoneId, isArchive: false },
{ $set: { isArchive: true } }
),
]);
}
// return {
// success: true,
// message: "zone deleted",
// data: deleteZone,
// organization: organization,
// };
return {
status: "Success",
data: deleteZone,
@@ -156,11 +158,6 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
return {
status: "Invalid zone ID",
};
// return {
// success: true,
// message: "Invalid zone ID",
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {
@@ -176,21 +173,19 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
};
export const GetZones = async (data: IGetZones): Promise<IResult> => {
try {
const { organization, userId } = data;
const { organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findZoneId = await zoneModel(organization)
.find()
.find({ projectId: projectId, isArchive: false })
.select(
"zoneId zoneName layer points viewPortCenter viewPortposition -_id"
);
if (!findZoneId) {
return { status: "Invalid zone" };
// res.status(500).json({ message: "Invalid zone" });
}
return { status: "Success", data: findZoneId };
// res.status(200).json({ data: findZoneId, organization: organization });
} catch (error: unknown) {
if (error instanceof Error) {
return {
@@ -211,6 +206,7 @@ export const ZoneData = async (data: IZone): Promise<IResult> => {
const findZone = await zoneModel(organization).findOne({
zoneId: zoneId,
projectId: projectId,
isArchive: false,
});
if (findZone)
return {
@@ -220,7 +216,6 @@ export const ZoneData = async (data: IZone): Promise<IResult> => {
else {
return { status: "Zone not found" };
}
// if (findZone) return res.status(200).json(findZone);
} catch (error: unknown) {
if (error instanceof Error) {
return {
@@ -249,7 +244,6 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
);
if (!existingZone) {
return { status: "Zone not found for the UUID" };
// return res.send({ message: "Zone not found for the UUID" });
} else {
const panelData = await panelModel(organization).find({
zoneId: zoneId,
@@ -289,7 +283,6 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
};
return { status: "Success", data: objectData };
// return res.status(200).json(objectData);
}
} catch (error: unknown) {
if (error instanceof Error) {
@@ -303,9 +296,9 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
}
}
};
export const VizZoneDatas = async (data: IZone): Promise<IResult> => {
export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
try {
const { organization, userId, projectId, zoneId } = data;
const { organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const existingZones = await zoneModel(organization)
@@ -318,7 +311,6 @@ export const VizZoneDatas = async (data: IZone): Promise<IResult> => {
);
if (!existingZones) {
return { status: "Zone not found for the UUID" };
// return res.send({ message: "Zone not found for the UUID" });
} else {
const response = await Promise.all(
existingZones.map(async (zone) => {
@@ -327,7 +319,6 @@ export const VizZoneDatas = async (data: IZone): Promise<IResult> => {
isArchive: false,
});
// Fetch widgets for each panel
const widgets = await Promise.all(
panelData.map(async (panel) => {
const widgetDataArray = await widgetModel(organization).find({
@@ -360,7 +351,6 @@ export const VizZoneDatas = async (data: IZone): Promise<IResult> => {
);
return { status: "Success", data: response };
// return res.status(200).json(response);
}
} catch (error: unknown) {
if (error instanceof Error) {