Builder Based projectID Service processing for camera,walll,lines, zones

This commit is contained in:
2025-05-28 13:01:55 +05:30
parent 2c28ffe9aa
commit 6b5bee879b
12 changed files with 453 additions and 44 deletions

View File

@@ -11,11 +11,10 @@ export const SetNewCamera = async (
res: Response
): Promise<void> => {
try {
const { organization, role, userId } = req.user || {};
const { organization, userId } = req.user || {};
const { position, target, rotation, projectId, versionId } = req.body;
if (
!organization ||
!role ||
!userId ||
!position ||
!target ||
@@ -35,7 +34,6 @@ export const SetNewCamera = async (
projectId,
versionId,
organization,
role,
userId,
};
const result = await SetCamera(data);
@@ -76,8 +74,8 @@ export const CameraList = async (
res: Response
): Promise<void> => {
try {
const { organization, role, userId } = req.user || {};
if (!organization || !role || !userId) {
const { organization, userId } = req.user || {};
if (!organization || !userId) {
res.status(400).json({
message: "All fields are required",
});
@@ -85,7 +83,6 @@ export const CameraList = async (
}
const result = await GetCamers({
organization,
role,
userId,
});

View File

@@ -6,7 +6,7 @@ import { Version } from "../Version/versionModel.ts";
export interface Zone extends Document {
zoneName: string;
zoneId: string;
zonePoints: [];
points: [];
viewPortCenter: [];
viewPortposition: [];
isArchive: boolean;

View File

@@ -1,9 +1,11 @@
import UsersDataModel from "../../V1Models/Auth/user.ts";
import cameraModel from "../../V1Models/Builder/cameraModel.ts";
import { existingProjectById } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IcameraData {
userId: string;
role: string;
position: Object;
target: Object;
rotation: Object;
@@ -13,8 +15,7 @@ interface IcameraData {
}
interface IgetCameras {
organization: string;
userId?: string;
role: string;
userId: string;
}
export const SetCamera = async (
data: IcameraData
@@ -22,7 +23,6 @@ export const SetCamera = async (
try {
const {
userId,
role,
position,
target,
rotation,
@@ -30,6 +30,8 @@ export const SetCamera = async (
projectId,
versionId,
} = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
@@ -84,8 +86,10 @@ export const SetCamera = async (
export const GetCamers = async (
data: IgetCameras
): Promise<{ status: string; data?: Object }> => {
const { userId, organization, role } = data;
const { userId, organization } = data;
try {
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findCamera = await cameraModel(organization).findOne({
userId: userId,
});
@@ -109,8 +113,10 @@ export const GetCamers = async (
export const onlineActiveDatas = async (
data: IgetCameras
): Promise<{ status: string; data?: Object }> => {
const { organization } = data;
const { organization, userId } = data;
try {
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findactiveUsers = await UsersDataModel(organization).find({
activeStatus: "online",
});

View File

@@ -1,4 +1,5 @@
import lineModel from "../../V1Models/Builder/linesModel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface ILineItems {
organization: string;
layer: number;
@@ -38,6 +39,8 @@ export const CreateLineItems = async (
): Promise<{ status: string; data?: Object }> => {
try {
const { organization, line, type, layer, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const newLine = await lineModel(organization).create({
layer,
line,
@@ -62,9 +65,11 @@ export const UpdateLineItems = async (
): Promise<{ status: string; data?: Object }> => {
try {
const { organization, projectId, uuid, position, userId } = data;
const updateResult = await lineModel(organization).updateMany(
{ "line.uuid": uuid, projectId: projectId }, // Filter: Find the line with the given uuid
{ $set: { "line.$.position": position } } // Update the position and type
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
await lineModel(organization).updateMany(
{ "line.uuid": uuid, projectId: projectId },
{ $set: { "line.$.position": position } }
);
// return {
// success: true,
@@ -93,11 +98,16 @@ export const DeleteLineItems = async (
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, line, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const inputUuids = line.map((item: any) => item.uuid);
const findValue = await lineModel(organization).findOneAndDelete({
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
});
const findValue = await lineModel(organization).findOneAndDelete(
{ projectId: projectId },
{
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
}
);
if (!findValue) {
return {
@@ -137,6 +147,8 @@ export const DeleteLayer = async (
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, layer, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await lineModel(organization).find({
layer: layer,
projectId: projectId,
@@ -146,7 +158,10 @@ export const DeleteLayer = async (
return { status: "layer not found" };
// return { success: false, message: "layer not found" };
} else {
await lineModel(organization).deleteMany({ layer: layer });
await lineModel(organization).deleteMany(
{ projectId: projectId },
{ layer: layer }
);
const updateResult = await lineModel(organization).updateMany(
{ layer: { $gt: layer } },
@@ -181,23 +196,30 @@ export const DeleteLinePoints = async (
): Promise<{ status: string; data?: object }> => {
try {
const { organization, projectId, uuid, userId } = data;
const findValue = await lineModel(organization).deleteMany({
"line.uuid": uuid,
});
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await lineModel(organization).deleteMany(
{ projectId: projectId },
{
"line.uuid": uuid,
}
);
if (!findValue) {
return {
success: false,
message: "line not found",
organization: organization,
};
return { status: "Line not found" };
// return {
// success: false,
// message: "line not found",
// organization: organization,
// };
} else {
return {
success: true,
message: "point deleted",
data: uuid,
organization: organization,
};
return { status: "Success" };
// return {
// success: true,
// message: "point deleted",
// data: uuid,
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {

View File

@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IWallSetupData {
modelUuid: string;
modelName: string;
@@ -11,10 +11,10 @@ interface IWallSetupData {
scale: [];
organization: string;
projectId: string;
userId: string;
}
interface IWallGet {
userId: string;
role: string;
organization: string;
projectId: string;
}
@@ -22,7 +22,6 @@ interface IWallDelete {
userId: string;
modelUuid: string;
modelName: string;
role: string;
organization: string;
projectId: string;
}
@@ -34,6 +33,7 @@ export class WallItems {
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
try {
const {
userId,
modelUuid,
modelName,
position,
@@ -45,6 +45,8 @@ export class WallItems {
projectId,
organization,
} = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findvalue = await wallItemModel(organization).findOne({
modelUuid: modelUuid,
});
@@ -100,9 +102,12 @@ export class WallItems {
}
static async getWallItems(data: IWallGet) {
try {
const { organization, role, userId, projectId } = data;
const findValue = await wallItemModel(organization).find();
const { organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await wallItemModel(organization).find({
projectId: projectId,
});
if (!findValue) {
return {
status: "wallitems not found",
@@ -127,9 +132,9 @@ export class WallItems {
}
static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> {
try {
const { modelUuid, modelName, organization, userId, projectId, role } =
data;
const { modelUuid, modelName, organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await wallItemModel(organization).findOneAndDelete({
modelUuid: modelUuid,
modelName: modelName,

View File

@@ -0,0 +1,376 @@
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
import templateModel from "../../V1Models/Vizualization/templatemodel.ts";
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface ISetZone {
organization: string;
projectId: string;
zoneData: {
zoneId: string;
points: [];
zoneName: string;
layer: number;
viewPortCenter: [];
viewPortposition: [];
};
userId: string;
}
interface IZone {
organization: string;
projectId: string;
zoneId: string;
userId: string;
}
interface IResult {
status: string;
data?: object;
}
interface IGetZones {
organization: string;
userId: string;
}
export const SetZone = async (data: ISetZone): Promise<IResult> => {
try {
const { organization, projectId, zoneData, userId } = data;
const zoneId = zoneData.zoneId;
const points = zoneData.points;
const zoneName = zoneData.zoneName;
const layer = zoneData.layer;
const viewPortCenter = zoneData.viewPortCenter;
const viewPortposition = zoneData.viewPortposition;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findZoneId = await zoneModel(organization).findOne({
projectId: projectId,
zoneId: zoneId,
});
if (findZoneId) {
const updateZone = await zoneModel(organization)
.findOneAndUpdate(
{ zoneId: zoneId, projectId: projectId },
{
points: points,
viewPortposition: viewPortposition,
viewPortCenter: viewPortCenter,
},
{ 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({
zoneId,
createdBy: userId,
projectId,
zoneName: zoneName,
points,
layer,
viewPortCenter,
viewPortposition,
});
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) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const DelZone = async (data: IZone): Promise<IResult> => {
try {
const { organization, userId, zoneId, projectId } = data;
const findZoneId = await zoneModel(organization).findOne({
zoneId: zoneId,
projectId: projectId,
});
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
if (findZoneId) {
const deleteZone = await zoneModel(organization)
.findOneAndDelete({
zoneId: zoneId,
createdBy: userId,
projectId: projectId,
isArchive: false,
})
.select("-_id -__v");
if (deleteZone) {
const panels = await panelModel(organization).find({ zoneId });
const allWidgetIds = panels.reduce((ids: string[], panel: any) => {
return ids.concat(panel.widgets || []);
}, []);
await widgetModel(organization).updateMany(
{ _id: { $in: allWidgetIds } },
{ $set: { isArchive: true } }
);
await panelModel(organization).updateMany(
{ zoneId },
{ $set: { isArchive: true } }
);
await Promise.all([
widget3dModel(organization).updateMany(
{ zoneId },
{ $set: { isArchive: true } }
),
templateModel(organization).updateMany(
{ zoneId },
{ $set: { isArchive: true } }
),
floatWidgetModel(organization).updateMany(
{ zoneId },
{ $set: { isArchive: true } }
),
]);
}
// return {
// success: true,
// message: "zone deleted",
// data: deleteZone,
// organization: organization,
// };
return {
status: "Success",
data: deleteZone,
};
} else {
return {
status: "Invalid zone ID",
};
// return {
// success: true,
// message: "Invalid zone ID",
// organization: organization,
// };
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const GetZones = async (data: IGetZones): Promise<IResult> => {
try {
const { organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findZoneId = await zoneModel(organization)
.find()
.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 {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const ZoneData = async (data: IZone): Promise<IResult> => {
try {
const { organization, userId, projectId, zoneId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findZone = await zoneModel(organization).findOne({
zoneId: zoneId,
projectId: projectId,
});
if (findZone)
return {
status: "Success",
data: findZone,
};
else {
return { status: "Zone not found" };
}
// if (findZone) return res.status(200).json(findZone);
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
try {
const { organization, userId, projectId, zoneId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const existingZone = await zoneModel(organization)
.findOne({
projectId: projectId,
zoneId: zoneId,
isArchive: false,
})
.select(
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points"
);
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,
isArchive: false,
});
const zoneName = existingZone.zoneName as string;
const widgets = await Promise.all(
panelData.map(async (data) => {
const widgetDataArray = await widgetModel(organization).find({
panelID: data._id,
isArchive: false,
});
return widgetDataArray.map((widgetData) => ({
id: widgetData.widgetID,
type: widgetData.elementType,
title: widgetData.widgetName,
panel: widgetData.widgetside,
data: widgetData.Data || [],
}));
})
);
const flattenedWidgets = widgets.flat();
const objectData = {
zoneName,
viewPortposition: existingZone.viewPortposition,
zoneId: existingZone.zoneId,
viewPortCenter: existingZone.viewPortCenter,
activeSides: existingZone.panelOrder || [],
panelOrder: existingZone.panelOrder || [],
lockedPanels: existingZone.lockedPanel || [],
points: existingZone.points || [],
widgets: flattenedWidgets,
};
return { status: "Success", data: objectData };
// return res.status(200).json(objectData);
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const VizZoneDatas = async (data: IZone): Promise<IResult> => {
try {
const { organization, userId, projectId, zoneId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const existingZones = await zoneModel(organization)
.find({
projectId: projectId,
isArchive: false,
})
.select(
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points"
);
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) => {
const panelData = await panelModel(organization).find({
zoneId: zone._id,
isArchive: false,
});
// Fetch widgets for each panel
const widgets = await Promise.all(
panelData.map(async (panel) => {
const widgetDataArray = await widgetModel(organization).find({
panelID: panel._id,
isArchive: false,
});
return widgetDataArray.map((widget) => ({
id: widget.widgetID,
type: widget.elementType,
title: widget.widgetName,
panel: widget.widgetside,
data: widget.Data || [],
}));
})
);
return {
zoneName: zone.zoneName,
zoneId: zone.zoneId,
viewPortposition: zone.viewPortposition,
viewPortCenter: zone.viewPortCenter,
activeSides: zone.panelOrder || [],
panelOrder: zone.panelOrder || [],
lockedPanels: zone.lockedPanel || [],
points: zone.points || [],
widgets: widgets.flat(),
};
})
);
return { status: "Success", data: response };
// return res.status(200).json(response);
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};

View File

@@ -0,0 +1,3 @@
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
// export const