callback function acknowledged in socket server of widget's
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
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,callback:any) => {
|
||||||
const { organization, widget, zoneId } = data;
|
const { organization, widget, zoneId } = data;
|
||||||
console.log("data: ", data);
|
// console.log("data: ", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
@@ -29,12 +29,20 @@ export const add3Dwidget = async (data: any) => {
|
|||||||
{ position: widget.position },
|
{ position: widget.position },
|
||||||
{ upsert: true, new: true }
|
{ upsert: true, new: true }
|
||||||
);
|
);
|
||||||
if (update3dwidget)
|
if (update3dwidget){
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: true,
|
||||||
|
message: "widget update successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "widget update successfully",
|
message: "widget update successfully",
|
||||||
organization: organization,
|
organization: organization,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -62,6 +70,11 @@ export const add3Dwidget = async (data: any) => {
|
|||||||
Data: newWidget3d.Data,
|
Data: newWidget3d.Data,
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
};
|
};
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: true,
|
||||||
|
message: "Widget created successfully",
|
||||||
|
})}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Widget created successfully",
|
message: "Widget created successfully",
|
||||||
@@ -80,7 +93,6 @@ export const add3Dwidget = async (data: any) => {
|
|||||||
};
|
};
|
||||||
export const update3D = async (data: any) => {
|
export const update3D = async (data: any) => {
|
||||||
const { organization, id, position, rotation, zoneId } = data;
|
const { organization, id, position, rotation, zoneId } = data;
|
||||||
console.log("data: ", data);
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
@@ -143,7 +155,6 @@ export const update3D = async (data: any) => {
|
|||||||
};
|
};
|
||||||
export const delete3Dwidget = async (data: any) => {
|
export const delete3Dwidget = async (data: any) => {
|
||||||
const { organization, id, zoneId } = data;
|
const { organization, id, zoneId } = data;
|
||||||
console.log("data: ", data);
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
|||||||
|
|
||||||
export const addfloat = async (data: any) => {
|
export const addfloat = async (data: any) => {
|
||||||
const { organization, widget, zoneId, index } = data;
|
const { organization, widget, zoneId, index } = data;
|
||||||
console.log("data:create ", data);
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
@@ -22,7 +21,6 @@ export const addfloat = async (data: any) => {
|
|||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
});
|
});
|
||||||
if (existingFloatWidget) {
|
if (existingFloatWidget) {
|
||||||
console.log("existingFloatWidget: ", existingFloatWidget);
|
|
||||||
const updateFloatWidget = await floatWidgetModel(
|
const updateFloatWidget = await floatWidgetModel(
|
||||||
organization
|
organization
|
||||||
).findOneAndUpdate(
|
).findOneAndUpdate(
|
||||||
@@ -51,7 +49,6 @@ export const addfloat = async (data: any) => {
|
|||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
zoneName: existingZone.zoneName,
|
zoneName: existingZone.zoneName,
|
||||||
};
|
};
|
||||||
console.log(updateFloatWidget);
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Widget updated successfully",
|
message: "Widget updated successfully",
|
||||||
@@ -99,9 +96,8 @@ export const addfloat = async (data: any) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const duplicatefloat = async (data: any) => {
|
export const duplicatefloat = async (data: any, callback: any) => {
|
||||||
const { organization, widget, zoneId, index } = data;
|
const { organization, widget, zoneId, index } = data;
|
||||||
console.log("data: ", data);
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
@@ -143,6 +139,12 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (!updateFloatWidget) {
|
if (!updateFloatWidget) {
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: false,
|
||||||
|
message: "FloatWidget update unsuccessfull",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "FloatWidget update unsuccessfull",
|
message: "FloatWidget update unsuccessfull",
|
||||||
@@ -156,6 +158,12 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
zoneName: existingZone.zoneName,
|
zoneName: existingZone.zoneName,
|
||||||
};
|
};
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: true,
|
||||||
|
message: "Widget updated successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Widget updated successfully",
|
message: "Widget updated successfully",
|
||||||
@@ -177,7 +185,6 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
duration: widget?.Data?.duration,
|
duration: widget?.Data?.duration,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log("newFloadWidget: ", newFloadWidget);
|
|
||||||
if (newFloadWidget) {
|
if (newFloadWidget) {
|
||||||
const floatDatas = {
|
const floatDatas = {
|
||||||
widget: {
|
widget: {
|
||||||
@@ -192,6 +199,12 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
zoneName: existingZone.zoneName,
|
zoneName: existingZone.zoneName,
|
||||||
index: index,
|
index: index,
|
||||||
};
|
};
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: true,
|
||||||
|
message: "duplicate FloatWidget created successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "duplicate FloatWidget created successfully",
|
message: "duplicate FloatWidget created successfully",
|
||||||
@@ -200,6 +213,12 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: false,
|
||||||
|
message: error?.message || "Error occurred while float",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: error?.message || "Error occurred while float",
|
message: error?.message || "Error occurred while float",
|
||||||
@@ -209,14 +228,12 @@ export const duplicatefloat = async (data: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const deletefloat = async (data: any) => {
|
export const deletefloat = async (data: any) => {
|
||||||
console.log("data: ", data);
|
|
||||||
const { floatWidgetID, zoneId, organization } = data;
|
const { floatWidgetID, zoneId, organization } = data;
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
console.log("existingZone: ", existingZone);
|
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -228,7 +245,6 @@ export const deletefloat = async (data: any) => {
|
|||||||
floatWidgetID: floatWidgetID,
|
floatWidgetID: floatWidgetID,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
console.log("findfloatWidget: ", findfloatWidget);
|
|
||||||
if (!findfloatWidget)
|
if (!findfloatWidget)
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -244,7 +260,6 @@ export const deletefloat = async (data: any) => {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
if (widgetData) {
|
if (widgetData) {
|
||||||
console.log("widgetData: ", widgetData);
|
|
||||||
const floatDeleteData = {
|
const floatDeleteData = {
|
||||||
floatWidgetID: findfloatWidget.floatWidgetID,
|
floatWidgetID: findfloatWidget.floatWidgetID,
|
||||||
zoneId: findfloatWidget.zoneId,
|
zoneId: findfloatWidget.zoneId,
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||||
export const addWidget = async (data: any) => {
|
export const addWidget = async (data: any,callback:any) => {
|
||||||
const { organization, panel, zoneId, widget } = data;
|
const { organization, panel, zoneId, widget } = data;
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -54,6 +55,12 @@ export const addWidget = async (data: any) => {
|
|||||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||||
);
|
);
|
||||||
if (!updateWidget) {
|
if (!updateWidget) {
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: false,
|
||||||
|
message: "Widget update unsuccessfull",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "Widget update unsuccessfull",
|
message: "Widget update unsuccessfull",
|
||||||
@@ -95,12 +102,19 @@ export const addWidget = async (data: any) => {
|
|||||||
zoneId: existingZone.zoneId,
|
zoneId: existingZone.zoneId,
|
||||||
zoneName: existingZone.zoneName,
|
zoneName: existingZone.zoneName,
|
||||||
};
|
};
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback({
|
||||||
|
success: true,
|
||||||
|
message: "Widget created successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Widget created successfully",
|
message: "Widget created successfully",
|
||||||
data: finaldata,
|
data: finaldata,
|
||||||
organization: organization,
|
organization: organization,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -109,6 +123,10 @@ export const addWidget = async (data: any) => {
|
|||||||
organization: organization,
|
organization: organization,
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
callback({
|
||||||
|
success: false,
|
||||||
|
message: "widge not found",
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "widge not found",
|
message: "widge not found",
|
||||||
@@ -204,7 +222,6 @@ export const Widgetdelete = async (data: any) => {
|
|||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
zoneName: existingZone.zoneName,
|
zoneName: existingZone.zoneName,
|
||||||
};
|
};
|
||||||
console.log("formattedWidgets", widgetData1);
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "Widget deleted successfully",
|
message: "Widget deleted successfully",
|
||||||
|
|||||||
@@ -598,8 +598,7 @@ const panelHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const widgetHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
const widgetHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false,callback:any) => {
|
||||||
// console.log('data: ', data);
|
|
||||||
if (!data?.organization) {
|
if (!data?.organization) {
|
||||||
console.warn(`Missing organization for event: ${event}`);
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
return;
|
return;
|
||||||
@@ -608,7 +607,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
|||||||
let result;
|
let result;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENTS.addWidget: {
|
case EVENTS.addWidget: {
|
||||||
result = await addWidget(data);
|
result = await addWidget(data,callback);
|
||||||
// console.log('result: ', result);
|
// console.log('result: ', result);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -660,7 +659,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
const floatHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
const floatHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false,callback:any) => {
|
||||||
// console.log('data: ', data);
|
// console.log('data: ', data);
|
||||||
if (!data?.organization) {
|
if (!data?.organization) {
|
||||||
console.warn(`Missing organization for event: ${event}`);
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
@@ -715,7 +714,28 @@ const floatHandleEvent = async (event: string, socket: Socket, data: any, namesp
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case EVENTS.duplicatefloat: {
|
||||||
|
const result = await duplicatefloat(data,callback)
|
||||||
|
if (result) {
|
||||||
|
// console.log('result?.success: ', result.organization);
|
||||||
|
const responseEvent = EVENTS.duplicatefloatUpdateResponse
|
||||||
|
// console.log('responseEvent: ', responseEvent);
|
||||||
|
const organization = result?.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
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -797,35 +817,14 @@ const templateHandleEvent = async (event: string, socket: Socket, data: any, nam
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case EVENTS.duplicatefloat: {
|
|
||||||
const result = await duplicatefloat(data)
|
|
||||||
if (result) {
|
|
||||||
// console.log('result?.success: ', result.organization);
|
|
||||||
const responseEvent = EVENTS.duplicatefloatUpdateResponse
|
|
||||||
// console.log('responseEvent: ', responseEvent);
|
|
||||||
const organization = result?.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
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false) => {
|
const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, namespace: any, notifySender: boolean = false,callback:any ) => {
|
||||||
// console.log('data: ', data);
|
// console.log('data: ', data);
|
||||||
if (!data?.organization) {
|
if (!data?.organization) {
|
||||||
console.warn(`Missing organization for event: ${event}`);
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
@@ -835,7 +834,7 @@ const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, nam
|
|||||||
let result;
|
let result;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENTS.add3DWidget: {
|
case EVENTS.add3DWidget: {
|
||||||
result = await add3Dwidget(data);
|
result = await add3Dwidget(data,callback);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
const responseEvent = EVENTS.widget3DUpdateResponse
|
const responseEvent = EVENTS.widget3DUpdateResponse
|
||||||
@@ -1145,8 +1144,8 @@ export const initSocketServer = (httpServer: any) => {
|
|||||||
|
|
||||||
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
||||||
|
|
||||||
socket.onAny((event: string, data: any) => {
|
socket.onAny((event: string, data: any ,callback:any) => {
|
||||||
eventHandlers.forEach(handler => handler(event, socket, data, namespace,io));
|
eventHandlers.forEach(handler => handler(event, socket, data, namespace,io,callback));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle disconnection
|
// Handle disconnection
|
||||||
|
|||||||
Reference in New Issue
Block a user