panel.widgets socket creation
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
import { title } from "process";
|
||||
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) => {
|
||||
const { organization,panel,zoneId,widget,} = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found", organization: organization }
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
panelName: widget.panel,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
})
|
||||
if (!existingPanel)
|
||||
|
||||
return { success: false, message: "panelName not found",organization: organization}
|
||||
@@ -44,14 +51,14 @@ export const addWidget = async (data: any) => {
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
|
||||
return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization}
|
||||
return { success: true, 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,
|
||||
widgetName: widget.title,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
@@ -62,7 +69,15 @@ export const addWidget = async (data: any) => {
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
await existingPanel.save();
|
||||
return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization}
|
||||
const widgetData={
|
||||
type:newWidget.elementType,
|
||||
id:newWidget.widgetID,
|
||||
panel:newWidget.widgetside,
|
||||
title:newWidget.widgetName,
|
||||
}
|
||||
const finaldata={ widgetData:widgetData,zoneId:existingZone.zoneId,zoneName:existingZone.zoneName}
|
||||
// console.log('existingPanel: ', widgetData);
|
||||
return { success: true, message: "Widget created successfully",data:finaldata,organization: organization}
|
||||
}
|
||||
}
|
||||
return { success: false, message: "Type mismatch",organization: organization}
|
||||
@@ -116,4 +131,4 @@ export const Widgetdelete = async (data: any) => {
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user