widget 2d, floating Data model added
This commit is contained in:
@@ -129,10 +129,10 @@ export class widget3dService {
|
||||
widgetID: id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!widgetData) return res.send("WidgetID not found");
|
||||
if (!widgetData) return res.status(204).json({ message: "Widget not found" });
|
||||
const structureData = {
|
||||
measurements: widgetData?.Data.measurements,
|
||||
duration: widgetData?.Data.duration,
|
||||
measurements: widgetData?.Data?.measurements,
|
||||
duration: widgetData?.Data?.duration,
|
||||
};
|
||||
const widgetName = widgetData.widgetName;
|
||||
return res.status(200).json({ Data: structureData, widgetName });
|
||||
|
||||
@@ -127,11 +127,11 @@ export class floatWidgetService {
|
||||
})
|
||||
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return res.send([]);
|
||||
return res.status(204).json({ message: "Widget not found" });
|
||||
}
|
||||
const Datastructure = {
|
||||
measurements: widgetData?.Data.measurements || {},
|
||||
duration: widgetData?.Data.duration || "1h",
|
||||
measurements: widgetData?.Data?.measurements || {},
|
||||
duration: widgetData?.Data?.duration || "1h",
|
||||
};
|
||||
const header = widgetData?.header;
|
||||
return res.status(200).json({ Data: Datastructure, header });
|
||||
|
||||
@@ -50,14 +50,18 @@ export class widgetService {
|
||||
// widgetID: widget.id,
|
||||
widgetName: widget?.widgetName,
|
||||
Data: {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
measurements: widget?.Data?.measurements || {},
|
||||
duration: widget?.Data?.duration || "1h",
|
||||
},
|
||||
// isArchive: false,
|
||||
isArchive: false,
|
||||
},
|
||||
},
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
console.log("updateWidget: ", updateWidget);
|
||||
if (!updateWidget) {
|
||||
return res.json({ message: "Widget update unsuccessful" });
|
||||
}
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Widget updated successfully" });
|
||||
@@ -73,10 +77,10 @@ export class widgetService {
|
||||
widgetName: widget.title,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
// measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements || {},
|
||||
duration: widget?.Data?.duration || "1h",
|
||||
},
|
||||
});
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
|
||||
@@ -63,14 +63,14 @@ const zoneSchema: Schema = new Schema(
|
||||
isArchive: { type: Boolean, default: false },
|
||||
panelOrder: {
|
||||
type: [String],
|
||||
enum: ["left", "right", "up", "down"],
|
||||
enum: ["left", "right", "top", "bottom"],
|
||||
},
|
||||
viewPortCenter: { type: Array, required: true },
|
||||
viewPortposition: { type: Array, required: true },
|
||||
lockedPanel: {
|
||||
type: [String],
|
||||
default: [],
|
||||
enum: ["left", "right", "up", "down"],
|
||||
enum: ["left", "right", "top", "bottom"],
|
||||
},
|
||||
// createdBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
|
||||
// sceneID: { type: mongoose.Schema.Types.ObjectId, ref: "Scene" },
|
||||
|
||||
@@ -2,8 +2,7 @@ import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
export const add3Dwidget = async (data: any) => {
|
||||
const { organization, widget, zoneId } = data;
|
||||
console.log('data: ', data);
|
||||
|
||||
console.log("data: ", data);
|
||||
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
@@ -48,6 +47,10 @@ export const add3Dwidget = async (data: any) => {
|
||||
widgetID: widget.id,
|
||||
position: widget.position,
|
||||
zoneId,
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements || {},
|
||||
duration: widget?.Data?.duration || "1h",
|
||||
},
|
||||
});
|
||||
if (newWidget3d) {
|
||||
const widgemodel3D_Datas = {
|
||||
@@ -76,8 +79,8 @@ export const add3Dwidget = async (data: any) => {
|
||||
}
|
||||
};
|
||||
export const update3D = async (data: any) => {
|
||||
const { organization, id, position, rotation, zoneId } = data
|
||||
console.log('data: ', data);
|
||||
const { organization, id, position, rotation, zoneId } = data;
|
||||
console.log("data: ", data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
@@ -95,9 +98,7 @@ export const update3D = async (data: any) => {
|
||||
isArchive: false,
|
||||
});
|
||||
if (existing3Dwidget) {
|
||||
const update3dwidget = await widget3dModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||
{
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
@@ -106,8 +107,7 @@ export const update3D = async (data: any) => {
|
||||
{ position: position, rotation: rotation },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
if (update3dwidget){
|
||||
|
||||
if (update3dwidget) {
|
||||
const updateDatas = {
|
||||
widget: {
|
||||
id: update3dwidget.widgetID,
|
||||
@@ -120,16 +120,15 @@ export const update3D = async (data: any) => {
|
||||
return {
|
||||
success: true,
|
||||
message: "widget update successfully",
|
||||
data:updateDatas,
|
||||
data: updateDatas,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
message: "widget not found",
|
||||
|
||||
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
@@ -143,8 +142,8 @@ export const update3D = async (data: any) => {
|
||||
}
|
||||
};
|
||||
export const delete3Dwidget = async (data: any) => {
|
||||
const { organization, id, zoneId } = data
|
||||
console.log('data: ', data);
|
||||
const { organization, id, zoneId } = data;
|
||||
console.log("data: ", data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
@@ -177,19 +176,19 @@ export const delete3Dwidget = async (data: any) => {
|
||||
{ isArchive: true },
|
||||
{ new: true }
|
||||
);
|
||||
if (updateWidget){
|
||||
if (updateWidget) {
|
||||
const delete_Datas = {
|
||||
zoneId: zoneId,id:existing3Dwidget.widgetID
|
||||
zoneId: zoneId,
|
||||
id: existing3Dwidget.widgetID,
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data:delete_Datas,
|
||||
data: delete_Datas,
|
||||
message: "3DWidget delete successfull",
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -198,5 +197,4 @@ export const delete3Dwidget = async (data: any) => {
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -2,178 +2,266 @@ import floatWidgetModel from "../../../shared/model/vizualization/floatWidget.ts
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
|
||||
export const addfloat = async (data: any) => {
|
||||
const { organization, widget, zoneId, index } = data;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
const { organization, widget, zoneId, index } = data;
|
||||
console.log('data:create ', data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return {
|
||||
success: false,
|
||||
message: "Zone not found for the zoneId",
|
||||
organization: organization,
|
||||
};
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
console.log('existingFloatWidget: ', existingFloatWidget);
|
||||
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements,
|
||||
duration: widget?.Data?.duration,
|
||||
},
|
||||
header: widget?.header,
|
||||
position: widget?.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
const floatUpdateDatas = {
|
||||
position: updateFloatWidget.position,
|
||||
index: index,
|
||||
zoneId: zoneId, zoneName: existingZone.zoneName
|
||||
}
|
||||
console.log(updateFloatWidget);
|
||||
return { success: true, message: "Widget updated successfully", data: floatUpdateDatas, organization: organization }
|
||||
}else{
|
||||
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
const floatDatas = {
|
||||
widget: {
|
||||
position: newFloadWidget.position, header: newFloadWidget.header, value: newFloadWidget.value
|
||||
, per: newFloadWidget.per, className: newFloadWidget.className, id: newFloadWidget.floatWidgetID
|
||||
},
|
||||
zoneId: zoneId, zoneName: existingZone.zoneName
|
||||
}
|
||||
return { success: true, message: "FloatWidget created successfully", data: floatDatas, organization: organization }
|
||||
}
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
console.log("existingFloatWidget: ", existingFloatWidget);
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements,
|
||||
duration: widget?.Data?.duration,
|
||||
},
|
||||
header: widget?.header,
|
||||
position: widget?.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||
);
|
||||
const floatUpdateDatas = {
|
||||
position: updateFloatWidget.position,
|
||||
index: index,
|
||||
zoneId: zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
console.log(updateFloatWidget);
|
||||
return {
|
||||
success: true,
|
||||
message: "Widget updated successfully",
|
||||
data: floatUpdateDatas,
|
||||
organization: organization,
|
||||
};
|
||||
} else {
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
const floatDatas = {
|
||||
widget: {
|
||||
position: newFloadWidget.position,
|
||||
header: newFloadWidget.header,
|
||||
value: newFloadWidget.value,
|
||||
per: newFloadWidget.per,
|
||||
className: newFloadWidget.className,
|
||||
id: newFloadWidget.floatWidgetID,
|
||||
},
|
||||
zoneId: zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
message: "FloatWidget created successfully",
|
||||
data: floatDatas,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "Error occurred while float",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
};
|
||||
export const duplicatefloat = async (data: any) => {
|
||||
const { organization, widget, zoneId, index } = data;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
const { organization, widget, zoneId, index } = data;
|
||||
console.log("data: ", data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return {
|
||||
success: false,
|
||||
message: "Zone not found for the zoneId",
|
||||
organization: organization,
|
||||
};
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements,
|
||||
duration: widget?.Data?.duration,
|
||||
},
|
||||
header: widget?.header,
|
||||
position: widget?.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
const floatUpdateDatas = {
|
||||
position: updateFloatWidget.position,
|
||||
index: index,
|
||||
zoneId: zoneId, zoneName: existingZone.zoneName
|
||||
}
|
||||
return { success: true, message: "Widget updated successfully", data: floatUpdateDatas, organization: organization }
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements,
|
||||
duration: widget?.Data?.duration,
|
||||
},
|
||||
header: widget?.header,
|
||||
position: widget?.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
const floatDatas = {
|
||||
widget: {
|
||||
position: newFloadWidget.position, header: newFloadWidget.header, value: newFloadWidget.value
|
||||
, per: newFloadWidget.per, className: newFloadWidget.className, id: newFloadWidget.floatWidgetID
|
||||
},
|
||||
zoneId: zoneId, zoneName: existingZone.zoneName,index:index
|
||||
}
|
||||
return { success: true, message: "duplicate FloatWidget created successfully", data: floatDatas, organization: organization }
|
||||
}
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||
);
|
||||
if (!updateFloatWidget) {
|
||||
return {
|
||||
success: false,
|
||||
message: "FloatWidget update unsuccessfull",
|
||||
// data: updateWidget,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
const floatUpdateDatas = {
|
||||
position: updateFloatWidget.position,
|
||||
index: index,
|
||||
zoneId: zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
message: "Widget updated successfully",
|
||||
data: floatUpdateDatas,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements,
|
||||
duration: widget?.Data?.duration,
|
||||
},
|
||||
});
|
||||
console.log("newFloadWidget: ", newFloadWidget);
|
||||
if (newFloadWidget) {
|
||||
const floatDatas = {
|
||||
widget: {
|
||||
position: newFloadWidget.position,
|
||||
header: newFloadWidget.header,
|
||||
value: newFloadWidget.value,
|
||||
per: newFloadWidget.per,
|
||||
className: newFloadWidget.className,
|
||||
id: newFloadWidget.floatWidgetID,
|
||||
},
|
||||
zoneId: zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
index: index,
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
message: "duplicate FloatWidget created successfully",
|
||||
data: floatDatas,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "Error occurred while float",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
};
|
||||
export const deletefloat = async (data: any) => {
|
||||
const { floatWidgetID, zoneId, organization } = data;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
|
||||
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: floatWidgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findfloatWidget)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
const widgetData = await floatWidgetModel(organization).updateOne(
|
||||
{ _id: findfloatWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
const floatDeleteData = {
|
||||
floatWidgetID: findfloatWidget.floatWidgetID,
|
||||
zoneId: findfloatWidget.zoneId,
|
||||
zoneName: existingZone.zoneName
|
||||
|
||||
}
|
||||
return { success: true, message: "FloatingWidget deleted successfully", data: floatDeleteData, organization: organization }
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||
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,
|
||||
message: "Zone not found for the zoneId",
|
||||
organization: organization,
|
||||
};
|
||||
|
||||
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: floatWidgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
console.log("findfloatWidget: ", findfloatWidget);
|
||||
if (!findfloatWidget)
|
||||
return {
|
||||
success: false,
|
||||
message: "Zone not found for the zoneId",
|
||||
organization: organization,
|
||||
};
|
||||
const widgetData = await floatWidgetModel(organization).findByIdAndUpdate(
|
||||
{ _id: findfloatWidget._id, isArchive: false },
|
||||
{ isArchive: true },
|
||||
{ new: true }
|
||||
);
|
||||
// if(!widgetData) {
|
||||
// return
|
||||
// }
|
||||
if (widgetData) {
|
||||
console.log("widgetData: ", widgetData);
|
||||
const floatDeleteData = {
|
||||
floatWidgetID: findfloatWidget.floatWidgetID,
|
||||
zoneId: findfloatWidget.zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
message: "FloatingWidget deleted successfully",
|
||||
data: floatDeleteData,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "Error occurred while float",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,23 +2,29 @@ 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
|
||||
const { organization, panel, zoneId, widget } = data;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found", organization: organization }
|
||||
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 }
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "panelName not found",
|
||||
organization: organization,
|
||||
};
|
||||
|
||||
if (existingPanel.panelName === widget.panel) {
|
||||
const existingWidget = await widgetSchema(organization).findOne({
|
||||
@@ -28,9 +34,7 @@ export const addWidget = async (data: any) => {
|
||||
// widgetOrder: widget.widgetOrder,
|
||||
});
|
||||
if (existingWidget) {
|
||||
const updateWidget = await widgetSchema(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
const updateWidget = await widgetSchema(organization).findOneAndUpdate(
|
||||
{
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
@@ -41,17 +45,28 @@ export const addWidget = async (data: any) => {
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
Data: {
|
||||
measurements: widget.Data.measurements,
|
||||
duration: widget.Data.duration,
|
||||
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: true, message: "Widget updated successfully", data: updateWidget, organization: organization }
|
||||
|
||||
if (!updateWidget) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Widget update unsuccessfull",
|
||||
// data: updateWidget,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
message: "Widget updated successfully",
|
||||
data: updateWidget,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widget.id,
|
||||
@@ -60,11 +75,11 @@ export const addWidget = async (data: any) => {
|
||||
widgetName: widget.title,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
zoneId: zoneId
|
||||
// Data: {
|
||||
// measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1hr",
|
||||
// },
|
||||
zoneId: zoneId,
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements || {},
|
||||
duration: widget?.Data?.duration || "1hr",
|
||||
},
|
||||
});
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
@@ -74,35 +89,60 @@ export const addWidget = async (data: any) => {
|
||||
id: newWidget.widgetID,
|
||||
panel: newWidget.widgetside,
|
||||
title: newWidget.widgetName,
|
||||
}
|
||||
const finaldata = { widgetData: widgetData, zoneId: existingZone.zoneId, zoneName: existingZone.zoneName }
|
||||
return { success: true, message: "Widget created successfully", data: finaldata, organization: organization }
|
||||
};
|
||||
const finaldata = {
|
||||
widgetData: widgetData,
|
||||
zoneId: existingZone.zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
message: "Widget created successfully",
|
||||
data: finaldata,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
return { success: false, message: "Type mismatch", organization: organization }
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "Type mismatch",
|
||||
organization: organization,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return { success: false, message: 'widge not found', error, organization: organization }
|
||||
return {
|
||||
success: false,
|
||||
message: "widge not found",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const Widgetdelete = async (data: any) => {
|
||||
const { widgetID, zoneId, organization } = data
|
||||
const { widgetID, zoneId, organization } = data;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found", organization: organization }
|
||||
return {
|
||||
success: false,
|
||||
message: "Zone not found",
|
||||
organization: organization,
|
||||
};
|
||||
const findWidget = await widgetSchema(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget)
|
||||
return { success: false, message: "Widget not found", organization: organization }
|
||||
return {
|
||||
success: false,
|
||||
message: "Widget not found",
|
||||
organization: organization,
|
||||
};
|
||||
const widgetData = await widgetSchema(organization).updateOne(
|
||||
{ _id: findWidget._id, isArchive: false,zoneId: zoneId },
|
||||
{ _id: findWidget._id, isArchive: false, zoneId: zoneId },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
@@ -112,7 +152,6 @@ export const Widgetdelete = async (data: any) => {
|
||||
panelID: findWidget.panelID,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
|
||||
});
|
||||
// console.log('widgets: ', widgets);
|
||||
// .sort({ widgetOrder: 1 });
|
||||
@@ -125,7 +164,7 @@ export const Widgetdelete = async (data: any) => {
|
||||
const panelData = await panelSchema(organization).findOne({
|
||||
_id: findWidget.panelID,
|
||||
isArchive: false,
|
||||
zoneId: zoneId
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (panelData.widgets.includes(findWidget._id)) {
|
||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||
@@ -161,15 +200,24 @@ export const Widgetdelete = async (data: any) => {
|
||||
},
|
||||
}));
|
||||
const widgetData1 = {
|
||||
widgetDeleteDatas: formattedWidgets, zoneId: zoneId, zoneName: existingZone.zoneName
|
||||
|
||||
}
|
||||
console.log("formattedWidgets",widgetData1);
|
||||
return { success: true, message: "Widget deleted successfully", data: widgetData1, organization: organization }
|
||||
|
||||
widgetDeleteDatas: formattedWidgets,
|
||||
zoneId: zoneId,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
console.log("formattedWidgets", widgetData1);
|
||||
return {
|
||||
success: true,
|
||||
message: "Widget deleted successfully",
|
||||
data: widgetData1,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "An unknown error occurred.", error, organization: organization }
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "An unknown error occurred.",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user