widget3d update,delete creation
This commit is contained in:
16
.env
16
.env
@@ -1,11 +1,11 @@
|
|||||||
# MONGO_URI=mongodb://192.168.0.111/
|
MONGO_URI=mongodb://192.168.0.111/
|
||||||
# MONGO_USER=mydata
|
MONGO_USER=mydata
|
||||||
# MONGO_PASSWORD=mongodb@hexr2002
|
MONGO_PASSWORD=mongodb@hexr2002
|
||||||
# MONGO_AUTH_DB=admin
|
|
||||||
|
|
||||||
MONGO_USER=admin
|
|
||||||
MONGO_PASSWORD=admin321
|
|
||||||
MONGO_AUTH_DB=admin
|
MONGO_AUTH_DB=admin
|
||||||
MONGO_URI=mongodb://mongo/
|
|
||||||
|
# MONGO_USER=admin
|
||||||
|
# MONGO_PASSWORD=admin321
|
||||||
|
# MONGO_AUTH_DB=admin
|
||||||
|
# MONGO_URI=mongodb://mongo/
|
||||||
API_PORT=5000
|
API_PORT=5000
|
||||||
SOCKET_PORT=8000
|
SOCKET_PORT=8000
|
||||||
@@ -2,6 +2,8 @@ import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
|||||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||||
export const add3Dwidget = async (data: any) => {
|
export const add3Dwidget = async (data: any) => {
|
||||||
const { organization, widget, zoneId } = data;
|
const { organization, widget, zoneId } = data;
|
||||||
|
console.log('data: ', data);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
@@ -73,3 +75,128 @@ export const add3Dwidget = async (data: any) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const update3D = async (data: any) => {
|
||||||
|
const { organization, id, position, rotation, zoneId } = data
|
||||||
|
console.log('data: ', data);
|
||||||
|
try {
|
||||||
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingZone)
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Zone not found",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
|
widgetID: id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existing3Dwidget) {
|
||||||
|
const update3dwidget = await widget3dModel(
|
||||||
|
organization
|
||||||
|
).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
widgetID: id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{ position: position, rotation: rotation },
|
||||||
|
{ upsert: true, new: true }
|
||||||
|
);
|
||||||
|
if (update3dwidget){
|
||||||
|
|
||||||
|
const updateDatas = {
|
||||||
|
widget: {
|
||||||
|
id: update3dwidget.widgetID,
|
||||||
|
type: update3dwidget.type,
|
||||||
|
position: update3dwidget.position,
|
||||||
|
rotation: update3dwidget.rotation,
|
||||||
|
},
|
||||||
|
zoneId: zoneId,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "widget update successfully",
|
||||||
|
data:updateDatas,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "widget not found",
|
||||||
|
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error?.message || "Error occurred while 3Dwidget",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const delete3Dwidget = async (data: any) => {
|
||||||
|
const { organization, id, zoneId } = data
|
||||||
|
console.log('data: ', data);
|
||||||
|
try {
|
||||||
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingZone)
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Zone not found",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
|
widgetID: id,
|
||||||
|
isArchive: false,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (!existing3Dwidget) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "3D widget not found for the ID",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
widgetID: id,
|
||||||
|
zoneId: zoneId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{ isArchive: true },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (updateWidget){
|
||||||
|
const delete_Datas = {
|
||||||
|
zoneId: zoneId,id:existing3Dwidget.widgetID
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data:delete_Datas,
|
||||||
|
message: "3DWidget delete successfull",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error?.message || "Error occurred while 3Dwidget",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const addfloat = async (data: any) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
if (existingFloatWidget) {
|
if (existingFloatWidget) {
|
||||||
|
console.log('existingFloatWidget: ', existingFloatWidget);
|
||||||
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
@@ -26,8 +27,8 @@ export const addfloat = async (data: any) => {
|
|||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
Data: {
|
Data: {
|
||||||
measurements: widget?.Data.measurements,
|
measurements: widget?.Data?.measurements,
|
||||||
duration: widget?.Data.duration,
|
duration: widget?.Data?.duration,
|
||||||
},
|
},
|
||||||
header: widget?.header,
|
header: widget?.header,
|
||||||
position: widget?.position,
|
position: widget?.position,
|
||||||
@@ -43,28 +44,31 @@ export const addfloat = async (data: any) => {
|
|||||||
index: index,
|
index: index,
|
||||||
zoneId: zoneId, zoneName: existingZone.zoneName
|
zoneId: zoneId, zoneName: existingZone.zoneName
|
||||||
}
|
}
|
||||||
|
console.log(updateFloatWidget);
|
||||||
return { success: true, message: "Widget updated successfully", data: floatUpdateDatas, organization: organization }
|
return { success: true, message: "Widget updated successfully", data: floatUpdateDatas, organization: organization }
|
||||||
|
}else{
|
||||||
|
|
||||||
|
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||||
|
className: widget.className,
|
||||||
|
header: widget.header,
|
||||||
|
floatWidgetID: widget.id,
|
||||||
|
position: widget.position,
|
||||||
|
per: widget.per,
|
||||||
|
value: widget.value,
|
||||||
|
zoneId: zoneId,
|
||||||
|
});
|
||||||
|
if (newFloadWidget) {
|
||||||
|
const floatDatas = {
|
||||||
|
widget: {
|
||||||
|
position: newFloadWidget.position, header: newFloadWidget.header, value: newFloadWidget.value
|
||||||
|
, per: newFloadWidget.per, className: newFloadWidget.className, id: newFloadWidget.floatWidgetID
|
||||||
|
},
|
||||||
|
zoneId: zoneId, zoneName: existingZone.zoneName
|
||||||
|
}
|
||||||
|
return { success: true, message: "FloatWidget created successfully", data: floatDatas, organization: organization }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
|
||||||
className: widget.className,
|
|
||||||
header: widget.header,
|
|
||||||
floatWidgetID: widget.id,
|
|
||||||
position: widget.position,
|
|
||||||
per: widget.per,
|
|
||||||
value: widget.value,
|
|
||||||
zoneId: zoneId,
|
|
||||||
});
|
|
||||||
if (newFloadWidget) {
|
|
||||||
const floatDatas = {
|
|
||||||
widget: {
|
|
||||||
position: newFloadWidget.position, header: newFloadWidget.header, value: newFloadWidget.value
|
|
||||||
, per: newFloadWidget.per, className: newFloadWidget.className, id: newFloadWidget.floatWidgetID
|
|
||||||
},
|
|
||||||
zoneId: zoneId, zoneName: existingZone.zoneName
|
|
||||||
}
|
|
||||||
return { success: true, message: "FloatWidget created successfully", data: floatDatas, organization: organization }
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||||
}
|
}
|
||||||
@@ -95,8 +99,8 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
Data: {
|
Data: {
|
||||||
measurements: widget?.Data.measurements,
|
measurements: widget?.Data?.measurements,
|
||||||
duration: widget?.Data.duration,
|
duration: widget?.Data?.duration,
|
||||||
},
|
},
|
||||||
header: widget?.header,
|
header: widget?.header,
|
||||||
position: widget?.position,
|
position: widget?.position,
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ export const EVENTS = {
|
|||||||
//3Dwidget
|
//3Dwidget
|
||||||
add3DWidget:"v2:viz-3D-widget:add",
|
add3DWidget:"v2:viz-3D-widget:add",
|
||||||
widget3DUpdateResponse:"viz-widget3D:response:updates",
|
widget3DUpdateResponse:"viz-widget3D:response:updates",
|
||||||
|
update3dPosition:"v2:viz-3D-widget:modifyPositionRotation",
|
||||||
|
update3dPositionResponse:"viz-widget3D:response:modifyPositionRotation",
|
||||||
|
delete3DWidget:"v2:viz-3D-widget:delete",
|
||||||
|
widget3DDeleteResponse:"viz-widget3D:response:delete",
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ import { addWidget, Widgetdelete } from '../services/visualization/widget-Servic
|
|||||||
import { addfloat, deletefloat, duplicatefloat } from '../services/visualization/floatWidget-Service.ts';
|
import { addfloat, deletefloat, duplicatefloat } from '../services/visualization/floatWidget-Service.ts';
|
||||||
import { addTemplate, addTemplateZone, TemplateZoneDelete } from '../services/visualization/templateServices.ts';
|
import { addTemplate, addTemplateZone, TemplateZoneDelete } from '../services/visualization/templateServices.ts';
|
||||||
import { deleteAssetModel, replaceEventDatas, setAssetModel } from '../services/assets/asset-Controller.ts';
|
import { deleteAssetModel, replaceEventDatas, setAssetModel } from '../services/assets/asset-Controller.ts';
|
||||||
import { add3Dwidget } from '../services/visualization/3dWidget-Service.ts';
|
import { add3Dwidget, delete3Dwidget, update3D } from '../services/visualization/3dWidget-Service.ts';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -814,6 +814,52 @@ const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, nam
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case EVENTS.update3dPosition: {
|
||||||
|
result = await update3D(data);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const responseEvent = EVENTS.update3dPositionResponse
|
||||||
|
const organization = result?.organization
|
||||||
|
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||||
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||||
|
if (organization) {
|
||||||
|
socket.to(organization).emit(responseEvent, {
|
||||||
|
success: result.success,
|
||||||
|
message: result.message,
|
||||||
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case EVENTS.delete3DWidget: {
|
||||||
|
result = await delete3Dwidget(data);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const responseEvent = EVENTS.widget3DDeleteResponse
|
||||||
|
const organization = result?.organization
|
||||||
|
// const emitTarget = notifySender ? socket.in(organization) : socket.to(organization);
|
||||||
|
// console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization));
|
||||||
|
if (organization) {
|
||||||
|
socket.to(organization).emit(responseEvent, {
|
||||||
|
success: result.success,
|
||||||
|
message: result.message,
|
||||||
|
data: result.data,
|
||||||
|
error: result.error || null,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn(`Organization missing in response for event: ${event}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// case EVENTS.deleteWidget: {
|
// case EVENTS.deleteWidget: {
|
||||||
// const result = await Widgetdelete(data)
|
// const result = await Widgetdelete(data)
|
||||||
@@ -1034,9 +1080,9 @@ export const initSocketServer = (httpServer: any) => {
|
|||||||
// console.log(`✅ Client connected to ${namespaceName}: ${socket.id}`);
|
// console.log(`✅ Client connected to ${namespaceName}: ${socket.id}`);
|
||||||
// Extract organization from query parameters
|
// Extract organization from query parameters
|
||||||
|
|
||||||
const organization = socket.handshake.query.organization as string;
|
// const organization = socket.handshake.query.organization as string;
|
||||||
const email = socket.handshake.query.email as string;
|
// const email = socket.handshake.query.email as string;
|
||||||
// const {organization,email} = socket.handshake.auth
|
const {organization,email} = socket.handshake.auth
|
||||||
// console.log(`🔍 Received organization: ${organization}`);
|
// console.log(`🔍 Received organization: ${organization}`);
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
@@ -1049,9 +1095,9 @@ export const initSocketServer = (httpServer: any) => {
|
|||||||
onlineUsers[organization] = new Set();
|
onlineUsers[organization] = new Set();
|
||||||
}
|
}
|
||||||
onlineUsers[organization].add(socket.id);
|
onlineUsers[organization].add(socket.id);
|
||||||
console.log('onlineUsers: ', onlineUsers);
|
// console.log('onlineUsers: ', onlineUsers);
|
||||||
|
|
||||||
console.log(`✅ User ${email} joined ${organization}. Active users:`, onlineUsers[organization]);
|
// console.log(`✅ User ${email} joined ${organization}. Active users:`, onlineUsers[organization]);
|
||||||
}
|
}
|
||||||
|
|
||||||
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
||||||
|
|||||||
Reference in New Issue
Block a user