diff --git a/.env b/.env index a592982..f3ab829 100644 --- a/.env +++ b/.env @@ -12,4 +12,15 @@ MONGO_AUTH_DB=admin # MONGO_AUTH_DB=admin MONGO_URI=mongodb://mongo/ API_PORT=5000 +======= +MONGO_URI=mongodb://192.168.0.111/ +MONGO_USER=mydata +MONGO_PASSWORD=mongodb@hexr2002 +MONGO_AUTH_DB=admin +# MONGO_USER=admin +# MONGO_PASSWORD=admin321 +# MONGO_AUTH_DB=admin +# MONGO_URI=mongodb://mongo/ +API_PORT=5000 +>>>>>>> Stashed changes SOCKET_PORT=8000 \ No newline at end of file diff --git a/src/socket-server/services/visualization/widget-Services.ts b/src/socket-server/services/visualization/widget-Services.ts index 043fafc..697fe4b 100644 --- a/src/socket-server/services/visualization/widget-Services.ts +++ b/src/socket-server/services/visualization/widget-Services.ts @@ -1,119 +1,119 @@ -import panelSchema from "../../../shared/model/vizualization/panelmodel.ts"; -import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; -export const addWidget = async (data: any) => { - const { organization,panel,zoneId,widget,} = data - console.log('data: ', data); - try { - const existingPanel = await panelSchema(organization).findOne({ - panelName: widget.panel, - zoneId: zoneId, - isArchive: false, - }); - if (!existingPanel) - - return { success: false, message: "panelName not found",organization: organization} - - - if (existingPanel.panelName === widget.panel) { - const existingWidget = await widgetSchema(organization).findOne({ - panelID: existingPanel._id, - widgetID: widget.id, - isArchive: false, - // widgetOrder: widget.widgetOrder, - }); - if (existingWidget) { - const updateWidget = await widgetSchema( - organization - ).findOneAndUpdate( - { - panelID: existingPanel._id, - widgetID: widget.id, - isArchive: false, - }, - { - $set: { - panelID: existingPanel._id, - widgetID: widget.id, - Data: { - measurements: widget.Data.measurements, - duration: widget.Data.duration, - }, - isArchive: false, - }, - }, - { upsert: true, new: true } // Upsert: create if not exists, new: return updated document - ); - - return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization} - - } - const newWidget = await widgetSchema(organization).create({ - widgetID: widget.id, - elementType: widget.type, - // widgetOrder: widgetOrder, - widgetName: widget.widgetName, - panelID: existingPanel._id, - widgetside: widget.panel, - // Data: { - // measurements: widget.Data.measurements || {}, - // duration: widget.Data.duration || "1hr", - // }, - }); - if (newWidget) { - existingPanel.widgets.push(newWidget._id); - await existingPanel.save(); - return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization} - } - } - return { success: false, message: "Type mismatch",organization: organization} - - } catch (error: any) { - return { success: false, message: 'widge not found', error,organization: organization } - } -} -export const Widgetdelete = async (data: any) => { - const { widgetID, organization } = data - console.log('data: ', data); - try { - const findWidget = await widgetSchema(organization).findOne({ - widgetID: widgetID, - isArchive: false, - }); - if (!findWidget) - return { success: false, message: "Widget not found",organization: organization} - const widgetData = await widgetSchema(organization).updateOne( - { _id: findWidget._id, isArchive: false }, - { $set: { isArchive: true } } - ); - - if (widgetData) { - // Find all widgets in the same panel and sort them by widgetOrder - const widgets = await widgetSchema(organization).find({ - panelID: findWidget.panelID, - isArchive: false, - }); - // .sort({ widgetOrder: 1 }); - - // Reassign widgetOrder values - // for (let i = 0; i < widgets.length; i++) { - // widgets[i].widgetOrder = (i + 1).toString(); // Convert to string - // await widgets[i].save(); - // } - const panelData = await panelSchema(organization).findOne({ - _id: findWidget.panelID, - isArchive: false, - }); - if (panelData.widgets.includes(findWidget._id)) { - const index1 = panelData.widgets.indexOf(findWidget._id); - panelData.widgets.splice(index1, 1); - } - const panelDeletedata = await panelData.save(); - console.log('Widget deleted successfully: '); - return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization} - - } - - } catch (error: any) { - return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization} - } +import panelSchema from "../../../shared/model/vizualization/panelmodel.ts"; +import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; +export const addWidget = async (data: any) => { + const { organization,panel,zoneId,widget,} = data + console.log('data: ', data); + try { + const existingPanel = await panelSchema(organization).findOne({ + panelName: widget.panel, + zoneId: zoneId, + isArchive: false, + }); + if (!existingPanel) + + return { success: false, message: "panelName not found",organization: organization} + + + if (existingPanel.panelName === widget.panel) { + const existingWidget = await widgetSchema(organization).findOne({ + panelID: existingPanel._id, + widgetID: widget.id, + isArchive: false, + // widgetOrder: widget.widgetOrder, + }); + if (existingWidget) { + const updateWidget = await widgetSchema( + organization + ).findOneAndUpdate( + { + panelID: existingPanel._id, + widgetID: widget.id, + isArchive: false, + }, + { + $set: { + panelID: existingPanel._id, + widgetID: widget.id, + Data: { + measurements: widget.Data.measurements, + duration: widget.Data.duration, + }, + isArchive: false, + }, + }, + { upsert: true, new: true } // Upsert: create if not exists, new: return updated document + ); + + return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization} + + } + const newWidget = await widgetSchema(organization).create({ + widgetID: widget.id, + elementType: widget.type, + // widgetOrder: widgetOrder, + widgetName: widget.widgetName, + panelID: existingPanel._id, + widgetside: widget.panel, + // Data: { + // measurements: widget.Data.measurements || {}, + // duration: widget.Data.duration || "1hr", + // }, + }); + if (newWidget) { + existingPanel.widgets.push(newWidget._id); + await existingPanel.save(); + return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization} + } + } + return { success: false, message: "Type mismatch",organization: organization} + + } catch (error: any) { + return { success: false, message: 'widge not found', error,organization: organization } + } +} +export const Widgetdelete = async (data: any) => { + const { widgetID, organization } = data + console.log('data: ', data); + try { + const findWidget = await widgetSchema(organization).findOne({ + widgetID: widgetID, + isArchive: false, + }); + if (!findWidget) + return { success: false, message: "Widget not found",organization: organization} + const widgetData = await widgetSchema(organization).updateOne( + { _id: findWidget._id, isArchive: false }, + { $set: { isArchive: true } } + ); + + if (widgetData) { + // Find all widgets in the same panel and sort them by widgetOrder + const widgets = await widgetSchema(organization).find({ + panelID: findWidget.panelID, + isArchive: false, + }); + // .sort({ widgetOrder: 1 }); + + // Reassign widgetOrder values + // for (let i = 0; i < widgets.length; i++) { + // widgets[i].widgetOrder = (i + 1).toString(); // Convert to string + // await widgets[i].save(); + // } + const panelData = await panelSchema(organization).findOne({ + _id: findWidget.panelID, + isArchive: false, + }); + if (panelData.widgets.includes(findWidget._id)) { + const index1 = panelData.widgets.indexOf(findWidget._id); + panelData.widgets.splice(index1, 1); + } + const panelDeletedata = await panelData.save(); + console.log('Widget deleted successfully: '); + return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization} + + } + + } catch (error: any) { + return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization} + } } \ No newline at end of file