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