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

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
import lineModel from "../../V1Models/Builder/linesModel.ts"; import lineModel from "../../V1Models/Builder/linesModel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface ILineItems { interface ILineItems {
organization: string; organization: string;
layer: number; layer: number;
@@ -38,6 +39,8 @@ export const CreateLineItems = async (
): Promise<{ status: string; data?: Object }> => { ): Promise<{ status: string; data?: Object }> => {
try { try {
const { organization, line, type, layer, projectId, userId } = data; 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({ const newLine = await lineModel(organization).create({
layer, layer,
line, line,
@@ -62,9 +65,11 @@ export const UpdateLineItems = async (
): Promise<{ status: string; data?: Object }> => { ): Promise<{ status: string; data?: Object }> => {
try { try {
const { organization, projectId, uuid, position, userId } = data; const { organization, projectId, uuid, position, userId } = data;
const updateResult = await lineModel(organization).updateMany( const UserExists = await existingUser(userId, organization);
{ "line.uuid": uuid, projectId: projectId }, // Filter: Find the line with the given uuid if (!UserExists) return { status: "User not found" };
{ $set: { "line.$.position": position } } // Update the position and type await lineModel(organization).updateMany(
{ "line.uuid": uuid, projectId: projectId },
{ $set: { "line.$.position": position } }
); );
// return { // return {
// success: true, // success: true,
@@ -93,11 +98,16 @@ export const DeleteLineItems = async (
): Promise<{ status: string; data?: object }> => { ): Promise<{ status: string; data?: object }> => {
try { try {
const { organization, projectId, line, userId } = data; 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 inputUuids = line.map((item: any) => item.uuid);
const findValue = await lineModel(organization).findOneAndDelete({ const findValue = await lineModel(organization).findOneAndDelete(
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key { projectId: projectId },
}); {
"line.uuid": { $all: inputUuids }, // Ensure all UUIDs are present in the `line` key
}
);
if (!findValue) { if (!findValue) {
return { return {
@@ -137,6 +147,8 @@ export const DeleteLayer = async (
): Promise<{ status: string; data?: object }> => { ): Promise<{ status: string; data?: object }> => {
try { try {
const { organization, projectId, layer, userId } = data; 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({ const findValue = await lineModel(organization).find({
layer: layer, layer: layer,
projectId: projectId, projectId: projectId,
@@ -146,7 +158,10 @@ export const DeleteLayer = async (
return { status: "layer not found" }; return { status: "layer not found" };
// return { success: false, message: "layer not found" }; // return { success: false, message: "layer not found" };
} else { } else {
await lineModel(organization).deleteMany({ layer: layer }); await lineModel(organization).deleteMany(
{ projectId: projectId },
{ layer: layer }
);
const updateResult = await lineModel(organization).updateMany( const updateResult = await lineModel(organization).updateMany(
{ layer: { $gt: layer } }, { layer: { $gt: layer } },
@@ -181,23 +196,30 @@ export const DeleteLinePoints = async (
): Promise<{ status: string; data?: object }> => { ): Promise<{ status: string; data?: object }> => {
try { try {
const { organization, projectId, uuid, userId } = data; const { organization, projectId, uuid, userId } = data;
const findValue = await lineModel(organization).deleteMany({ const UserExists = await existingUser(userId, organization);
"line.uuid": uuid, if (!UserExists) return { status: "User not found" };
}); const findValue = await lineModel(organization).deleteMany(
{ projectId: projectId },
{
"line.uuid": uuid,
}
);
if (!findValue) { if (!findValue) {
return { return { status: "Line not found" };
success: false, // return {
message: "line not found", // success: false,
organization: organization, // message: "line not found",
}; // organization: organization,
// };
} else { } else {
return { return { status: "Success" };
success: true, // return {
message: "point deleted", // success: true,
data: uuid, // message: "point deleted",
organization: organization, // data: uuid,
}; // organization: organization,
// };
} }
} catch (error: unknown) { } catch (error: unknown) {
if (error instanceof Error) { 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 wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IWallSetupData { interface IWallSetupData {
modelUuid: string; modelUuid: string;
modelName: string; modelName: string;
@@ -11,10 +11,10 @@ interface IWallSetupData {
scale: []; scale: [];
organization: string; organization: string;
projectId: string; projectId: string;
userId: string;
} }
interface IWallGet { interface IWallGet {
userId: string; userId: string;
role: string;
organization: string; organization: string;
projectId: string; projectId: string;
} }
@@ -22,7 +22,6 @@ interface IWallDelete {
userId: string; userId: string;
modelUuid: string; modelUuid: string;
modelName: string; modelName: string;
role: string;
organization: string; organization: string;
projectId: string; projectId: string;
} }
@@ -34,6 +33,7 @@ export class WallItems {
static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> { static async setWallItems(data: IWallSetupData): Promise<IWallItemResult> {
try { try {
const { const {
userId,
modelUuid, modelUuid,
modelName, modelName,
position, position,
@@ -45,6 +45,8 @@ export class WallItems {
projectId, projectId,
organization, organization,
} = data; } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findvalue = await wallItemModel(organization).findOne({ const findvalue = await wallItemModel(organization).findOne({
modelUuid: modelUuid, modelUuid: modelUuid,
}); });
@@ -100,9 +102,12 @@ export class WallItems {
} }
static async getWallItems(data: IWallGet) { static async getWallItems(data: IWallGet) {
try { try {
const { organization, role, userId, projectId } = data; const { organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
const findValue = await wallItemModel(organization).find(); if (!UserExists) return { status: "User not found" };
const findValue = await wallItemModel(organization).find({
projectId: projectId,
});
if (!findValue) { if (!findValue) {
return { return {
status: "wallitems not found", status: "wallitems not found",
@@ -127,9 +132,9 @@ export class WallItems {
} }
static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> { static async deleteWallItems(data: IWallDelete): Promise<IWallItemResult> {
try { try {
const { modelUuid, modelName, organization, userId, projectId, role } = const { modelUuid, modelName, organization, userId, projectId } = data;
data; const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findValue = await wallItemModel(organization).findOneAndDelete({ const findValue = await wallItemModel(organization).findOneAndDelete({
modelUuid: modelUuid, modelUuid: modelUuid,
modelName: modelName, 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