From c15ca51b9ff4c859177a5a44ff93f05aa49fbc56 Mon Sep 17 00:00:00 2001 From: Nivetharamesh99 Date: Fri, 11 Apr 2025 09:23:44 +0530 Subject: [PATCH] zone response zone-points added --- .../controller/lines/zoneService.ts | 8 +- .../controller/visualization/widgetService.ts | 9 +- .../visualization/templateServices.ts | 98 +++++++++++++------ 3 files changed, 75 insertions(+), 40 deletions(-) diff --git a/src/api-server/controller/lines/zoneService.ts b/src/api-server/controller/lines/zoneService.ts index bc62aae..6f2a643 100644 --- a/src/api-server/controller/lines/zoneService.ts +++ b/src/api-server/controller/lines/zoneService.ts @@ -108,7 +108,7 @@ export class Zoneservice { isArchive: false, }) .select( - "panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition" + "panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points" ); if (!existingZone) { return res.send({ message: "Zone not found for the UUID" }); @@ -146,7 +146,7 @@ export class Zoneservice { activeSides: existingZone.panelOrder || [], panelOrder: existingZone.panelOrder || [], lockedPanels: existingZone.lockedPanel || [], - points: existingZone.zonePoints || [], + points: existingZone.points || [], widgets: flattenedWidgets, }; @@ -166,7 +166,7 @@ export class Zoneservice { isArchive: false, }) .select( - "panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition" + "panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points" ); if (!existingZones) { return res.send({ message: "Zone not found for the UUID" }); @@ -205,7 +205,7 @@ export class Zoneservice { activeSides: zone.panelOrder || [], panelOrder: zone.panelOrder || [], lockedPanels: zone.lockedPanel || [], - points: zone.zonePoints || [], + points: zone.points || [], widgets: widgets.flat(), }; }) diff --git a/src/api-server/controller/visualization/widgetService.ts b/src/api-server/controller/visualization/widgetService.ts index 4e2dcb4..b43c942 100644 --- a/src/api-server/controller/visualization/widgetService.ts +++ b/src/api-server/controller/visualization/widgetService.ts @@ -6,6 +6,7 @@ export class widgetService { static async addWidget(req: Request, res: Response): Promise { try { // console.log("req.body: ", req.body); + console.log("req.body: ", req.body); const { organization, // panel, @@ -57,7 +58,6 @@ export class widgetService { }, { upsert: true, new: true } // Upsert: create if not exists, new: return updated document ); - console.log("updateWidget: ", updateWidget); return res .status(200) .json({ message: "Widget updated successfully" }); @@ -95,8 +95,8 @@ export class widgetService { static async deleteWidget(req: Request, res: Response): Promise { try { - const { widgetID, organization,zoneId} = req.body; - console.log(' req.body: ', req.body); + const { widgetID, organization, zoneId } = req.body; + console.log(" req.body: ", req.body); const findWidget = await widgetSchema(organization).findOne({ zoneId: zoneId, widgetID: widgetID, @@ -105,7 +105,7 @@ export class widgetService { if (!findWidget) return res.status(409).json({ message: "Widget not found" }); const widgetData = await widgetSchema(organization).updateOne( - { _id: findWidget._id, isArchive: false,zoneId: zoneId }, + { _id: findWidget._id, isArchive: false, zoneId: zoneId }, { $set: { isArchive: true } } ); @@ -142,6 +142,7 @@ export class widgetService { static async updatewidget(req: Request, res: Response): Promise { try { + console.log("req.body: ", req.body); const { organization, widgetID, values } = req.body; const findwidget = await widgetSchema(organization).findOne({ widgetID: widgetID, diff --git a/src/socket-server/services/visualization/templateServices.ts b/src/socket-server/services/visualization/templateServices.ts index 604dd5a..8c86540 100644 --- a/src/socket-server/services/visualization/templateServices.ts +++ b/src/socket-server/services/visualization/templateServices.ts @@ -5,7 +5,7 @@ import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; import floatWidgetModel from "../../../shared/model/vizualization/floatWidget.ts"; export const addTemplate = async (data: any) => { const { organization, template, name, panelOrder, widgets, snapshot } = data; - console.log('data: ', data); + console.log("data: ", data); try { // console.log("req.body: ", req.body); const existingTemplate = await templateModel(organization).findOne({ @@ -14,7 +14,11 @@ export const addTemplate = async (data: any) => { }); if (existingTemplate) - return { success: false, message: "TemplateID alreay exists", organization: organization } + return { + success: false, + message: "TemplateID alreay exists", + organization: organization, + }; const newTemplate = await templateModel(organization).create({ templateID: template.id, templateName: template.name, @@ -46,14 +50,15 @@ export const addTemplate = async (data: any) => { organization: organization, }; } - } catch (error: any) { - return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } - + return { + success: false, + message: error?.message || "Error occurred while template", + error, + organization: organization, + }; } - - -} +}; export const addTemplateZone = async (data: any) => { const { zoneId, templateID, organization } = data; @@ -63,14 +68,22 @@ export const addTemplateZone = async (data: any) => { isArchive: false, }); if (!existingZone) - return { success: false, message: "Zone not found ", organization: organization } + return { + success: false, + message: "Zone not found ", + organization: organization, + }; const existingTemplate = await templateModel(organization).findOne({ templateID: templateID, isArchive: false, }); if (!existingTemplate) - return { success: false, message: "TemplateID not found", organization: organization } + return { + success: false, + message: "TemplateID not found", + organization: organization, + }; if (existingZone.panelOrder.length > 0) { existingZone.panelOrder = existingTemplate.panelOrder; @@ -147,9 +160,11 @@ export const addTemplateZone = async (data: any) => { } for (const floatData of existingTemplate.floatWidgets) { - const existingFloatWidget = await floatWidgetModel( - organization - ).findOne({ floatWidgetID: floatData.id, isArchive: false, zoneId }); + const existingFloatWidget = await floatWidgetModel(organization).findOne({ + floatWidgetID: floatData.id, + isArchive: false, + zoneId, + }); if (existingFloatWidget) continue; await floatWidgetModel(organization).create({ @@ -163,19 +178,33 @@ export const addTemplateZone = async (data: any) => { }); } const templateZoneDatas = { - template: { id: existingTemplate.templateID, name: existingTemplate.templateName, panelOrder: existingTemplate.panelOrder, widgets: existingTemplate.widgets, snapshot: existingTemplate.snapshot, floatingWidget: existingTemplate.floatWidgets }, - zoneId: existingZone.zoneId, zoneName: existingZone.zoneName - } - - - return { success: true, message: "Template placed in Zone", data: templateZoneDatas, organization: organization } + template: { + id: existingTemplate.templateID, + name: existingTemplate.templateName, + panelOrder: existingTemplate.panelOrder, + widgets: existingTemplate.widgets, + snapshot: existingTemplate.snapshot, + floatingWidget: existingTemplate.floatWidgets, + }, + zoneId: existingZone.zoneId, + zoneName: existingZone.zoneName, + }; + return { + success: true, + message: "Template placed in Zone", + data: templateZoneDatas, + organization: organization, + }; } catch (error: any) { - return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } + return { + success: false, + message: error?.message || "Error occurred while template", + error, + organization: organization, + }; } - - -} +}; export const TemplateZoneDelete = async (data: any) => { const { zoneId, templateID, organization } = data; try { @@ -189,16 +218,21 @@ export const TemplateZoneDelete = async (data: any) => { { $set: { isArchive: true } } ); if (newTemplate) { - - const TemplateDeleteData = existingTemplate.templateID - return { success: true, message: "Template deleted successfully", data: TemplateDeleteData, organization: organization } + const TemplateDeleteData = existingTemplate.templateID; + return { + success: true, + message: "Template deleted successfully", + data: TemplateDeleteData, + organization: organization, + }; } - - } } catch (error: any) { - return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } + return { + success: false, + message: error?.message || "Error occurred while template", + error, + organization: organization, + }; } - - -} \ No newline at end of file +};