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