Visualization Part 2d and floating API Completed. Template Save and Get API completed
This commit is contained in:
@@ -35,14 +35,24 @@ export class pointService {
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
triggers: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "Inherit",
|
||||
bufferTime: 0,
|
||||
// delay: "Inherit",
|
||||
// spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
uuid: "point1UUID",
|
||||
uuid: "point2UUID",
|
||||
position: [0, 0.85, 0],
|
||||
rotation: [0, 0, 0],
|
||||
actions: [
|
||||
@@ -56,14 +66,24 @@ export class pointService {
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
triggers: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "Inherit",
|
||||
bufferTime: 0,
|
||||
// delay: "Inherit",
|
||||
// spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
uuid: "point1UUID",
|
||||
uuid: "point3UUID",
|
||||
position: [0, 0.85, -2.2],
|
||||
rotation: [0, 0, 0],
|
||||
actions: [
|
||||
@@ -77,14 +97,23 @@ export class pointService {
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
triggers: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "Inherit",
|
||||
bufferTime: 0,
|
||||
// delay: "Inherit",
|
||||
// spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
],
|
||||
speed: 1,
|
||||
});
|
||||
}
|
||||
// else if (type === "Vehicle") {
|
||||
|
||||
@@ -4,10 +4,10 @@ import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class Zoneservice {
|
||||
static async addandUpdateZone(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.body.organization;
|
||||
const zoneDatas = req.body.zonesdata;
|
||||
|
||||
console.log("req.body: ", req.body);
|
||||
try {
|
||||
const organization = req.body.organization;
|
||||
const zoneDatas = req.body.zonesdata;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneDatas.zoneId,
|
||||
isArchive: false,
|
||||
@@ -43,6 +43,7 @@ export class Zoneservice {
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
console.log("replaceZone: ", replaceZone);
|
||||
if (!replaceZone)
|
||||
return res.status(404).json({ message: "Zone not updated" });
|
||||
else
|
||||
@@ -231,7 +232,8 @@ export class Zoneservice {
|
||||
|
||||
static async ZoneData(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.query.organization;
|
||||
console.log("req.params: ", req.params);
|
||||
const organization = req.params.organization;
|
||||
const zoneId = req.params.zoneId;
|
||||
const findZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
|
||||
@@ -10,9 +10,10 @@ export class assetsFloorservice {
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
position,
|
||||
speed,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
rotation,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
@@ -28,8 +29,8 @@ export class assetsFloorservice {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
assetPosition: assetPosition,
|
||||
assetRotation: assetRotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
@@ -37,95 +38,46 @@ export class assetsFloorservice {
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
} else {
|
||||
// const newValue = await assetModel(organization).create({
|
||||
// modeluuid,
|
||||
// modelfileID,
|
||||
// modelname,
|
||||
// position,
|
||||
// rotation,
|
||||
// isLocked,
|
||||
// isVisible,
|
||||
// points,
|
||||
// });
|
||||
|
||||
// for (const point of points) {
|
||||
// // Create actions if they exist
|
||||
// for (const action of point.actions || []) {
|
||||
// const actionData = await actionModel(organization).create({
|
||||
// pointsUUID: point.uuid,
|
||||
// actionUUID: action.uuid,
|
||||
// eventData: {
|
||||
// uuid: action.uuid,
|
||||
// type: action.type,
|
||||
// material: action.material,
|
||||
// delay: action.delay,
|
||||
// spawn_Interval: action.spawnInterval,
|
||||
// },
|
||||
// });
|
||||
|
||||
// // Push action ID to point
|
||||
// newValue.points
|
||||
// .find((p: any) => p.uuid === point.uuid)
|
||||
// ?.actions.push(actionData._id);
|
||||
// }
|
||||
|
||||
// // Create triggers if they exist
|
||||
// for (const trigger of point.triggers || []) {
|
||||
// const triggerData = await triggerModel(organization).create({
|
||||
// pointsUUID: point.uuid,
|
||||
// actionUUID: trigger.uuid,
|
||||
// triggerData: {
|
||||
// type: trigger.type,
|
||||
// },
|
||||
// });
|
||||
|
||||
// // Push trigger ID to point
|
||||
// newValue.points
|
||||
// .find((p: any) => p.uuid === point.uuid)
|
||||
// ?.triggers.push(triggerData._id);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Save the updated document
|
||||
// await newValue.save();
|
||||
|
||||
// res.status(201).json(newValue);
|
||||
|
||||
let pointRefs = [];
|
||||
|
||||
for (const point of points) {
|
||||
let actionRefs = [];
|
||||
let triggerRefs = [];
|
||||
|
||||
// Store Actions (Events)
|
||||
if (point.actions && point.actions.length > 0) {
|
||||
for (const action of point.actions) {
|
||||
const actionDoc = await actionModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
actionUUID: action.uuid,
|
||||
isArchive: false,
|
||||
eventData: [action], // Store the action data
|
||||
uuid: action.uuid,
|
||||
name: action.name,
|
||||
type: action.type,
|
||||
material: action.material,
|
||||
delay: action.delay,
|
||||
spawn_Interval: action.spawn_Interval,
|
||||
// eventData: [action],
|
||||
});
|
||||
await actionDoc.save();
|
||||
actionRefs.push(actionDoc._id); // Store reference
|
||||
actionRefs.push(actionDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
// Store Triggers
|
||||
if (point.triggers && point.triggers.length > 0) {
|
||||
for (const trigger of point.triggers) {
|
||||
const triggerDoc = await triggerModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
actionUUID: trigger.uuid,
|
||||
isArchive: false,
|
||||
triggerData: [trigger], // Store trigger data
|
||||
uuid: trigger.uuid,
|
||||
name: trigger.name,
|
||||
type: trigger.type,
|
||||
bufferTime: trigger.bufferTime,
|
||||
// triggerData: [trigger],
|
||||
});
|
||||
await triggerDoc.save();
|
||||
triggerRefs.push(triggerDoc._id); // Store reference
|
||||
triggerRefs.push(triggerDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
// Store the Point document
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position,
|
||||
@@ -135,13 +87,13 @@ export class assetsFloorservice {
|
||||
});
|
||||
}
|
||||
|
||||
// Store the main asset document
|
||||
const assetDoc = await assetModel(organization).create({
|
||||
modeluuid,
|
||||
speed,
|
||||
modelname,
|
||||
position,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
rotation,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
points: pointRefs,
|
||||
@@ -163,22 +115,29 @@ export class assetsFloorservice {
|
||||
const { organization } = req.params;
|
||||
const findValue = await assetModel(organization)
|
||||
.find()
|
||||
.select("-_id -__v")
|
||||
.select("-_id")
|
||||
.populate({
|
||||
path: "points",
|
||||
// model: assetModel(organization),
|
||||
select: "-_id",
|
||||
})
|
||||
.populate({
|
||||
path: "points.actions",
|
||||
select: "-_id",
|
||||
populate: {
|
||||
path: "eventData",
|
||||
select: "uuid type -_id",
|
||||
},
|
||||
model: actionModel(organization),
|
||||
// select: "-_id",
|
||||
// populate: {
|
||||
// path: "eventData",
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
// },
|
||||
})
|
||||
.populate({
|
||||
path: "points.triggers",
|
||||
select: "-_id",
|
||||
populate: {
|
||||
path: "triggerData",
|
||||
select: "uuid type -_id",
|
||||
},
|
||||
model: triggerModel(organization),
|
||||
// select: "-_id",
|
||||
// populate: {
|
||||
// path: "triggerData",
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
// },
|
||||
});
|
||||
if (!findValue) {
|
||||
res.status(200).json("floorItems not found");
|
||||
|
||||
201
src/api-server/controller/visualization/floatWidgetService.ts
Normal file
201
src/api-server/controller/visualization/floatWidgetService.ts
Normal file
@@ -0,0 +1,201 @@
|
||||
import { Request, Response } from "express";
|
||||
import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
export class floatWidgetService {
|
||||
static async addfloatWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, widget, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "Zone not found for the zoneId" });
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
// Data: {
|
||||
// // measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
position: widget.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
|
||||
return res.status(200).json({ message: "Widget updated successfully" });
|
||||
}
|
||||
|
||||
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) {
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "FloatWidget created successfully" });
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async getfloatWidget(req: Request, res: Response): Promise<any> {
|
||||
const { organization, zoneId } = req.params;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
const widgetData = await floatWidgetModel(organization)
|
||||
.find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return res.send([]);
|
||||
}
|
||||
|
||||
const formattedWidgets = widgetData.map((widget) => ({
|
||||
Data: {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
},
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
id: widget.floatWidgetID,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
}));
|
||||
return res.status(200).json(formattedWidgets);
|
||||
}
|
||||
|
||||
// static async deleteWidget(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { widgetID, organization } = req.body;
|
||||
// const findWidget = await widgetSchema(organization).findOne({
|
||||
// widgetID: widgetID,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!findWidget)
|
||||
// return res.status(409).json({ message: "Widget not found" });
|
||||
// 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);
|
||||
// }
|
||||
// await panelData.save();
|
||||
// }
|
||||
// return res.status(200).json({ message: "Widget deleted successfully" });
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
|
||||
// static async updatewidget(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization, widgetID, values } = req.body;
|
||||
// const findwidget = await widgetSchema(organization).findOne({
|
||||
// widgetID: widgetID,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!findwidget)
|
||||
// return res.status(404).send({ message: "Data not found" });
|
||||
// const updateData = {
|
||||
// widgetName: values.widgetName,
|
||||
// widgetSide: values.widgetSide, // Fixed typo from widgetside to widgetSide
|
||||
// elementType: values.type,
|
||||
// Data: {
|
||||
// measurement: values.Data.measurement,
|
||||
// duration: values.Data.duration,
|
||||
// },
|
||||
// elementColor: values.color,
|
||||
// fontFamily: values.fontFamily,
|
||||
// fontStyle: values.fontStyle,
|
||||
// fontWeight: values.fontWeight,
|
||||
// isArchive: false,
|
||||
// };
|
||||
|
||||
// const changedWidget = await widgetSchema(organization).findOneAndUpdate(
|
||||
// { widgetID: widgetID, isArchive: false },
|
||||
// updateData,
|
||||
// {
|
||||
// new: true,
|
||||
// upsert: true,
|
||||
// setDefaultsOnInsert: true,
|
||||
// }
|
||||
// );
|
||||
|
||||
// return res.status(200).json({
|
||||
// message: "Widget updated successfully",
|
||||
// });
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
|
||||
// static async getDatafromWidget(req: Request, res: Response): Promise<any> {
|
||||
// const { organization, widgetID } = req.params;
|
||||
// try {
|
||||
// const existingWidget = await widgetSchema(organization)
|
||||
// .findOne({
|
||||
// widgetID: widgetID,
|
||||
// isArchive: false,
|
||||
// })
|
||||
// .select("Data -_id");
|
||||
// const Datastructure = {
|
||||
// measurements: existingWidget.Data.measurements || {},
|
||||
// duration: existingWidget.Data.duration || "1h",
|
||||
// };
|
||||
|
||||
// if (existingWidget) return res.status(200).json({ Data: Datastructure });
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -95,12 +95,10 @@ export class panelService {
|
||||
}
|
||||
|
||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||
existingZone.panelOrder = existingZone.panelOrder.filter(
|
||||
(panel: any) => panel !== existingPanel.panelName
|
||||
);
|
||||
|
||||
await existingZone.save();
|
||||
const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||
existingZone.panelOrder.splice(index1, 1);
|
||||
}
|
||||
await existingZone.save();
|
||||
|
||||
return res.status(200).json({ message: "Panel deleted successfully" });
|
||||
} catch (error: any) {
|
||||
|
||||
43
src/api-server/controller/visualization/templateService.ts
Normal file
43
src/api-server/controller/visualization/templateService.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Request, Response } from "express";
|
||||
import templateModel from "../../../shared/model/vizualization/templatemodel.ts";
|
||||
|
||||
export class templateService {
|
||||
static async AddTemplate(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { organization, templateID, name, panelOrder, widgets, snapshot } =
|
||||
req.body;
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingTemplate)
|
||||
return res.status(409).json({ message: "TemplateID alreay exists" });
|
||||
const newTemplate = await templateModel(organization).create({
|
||||
templateID,
|
||||
name,
|
||||
panelOrder,
|
||||
widgets,
|
||||
snapshot,
|
||||
});
|
||||
if (newTemplate)
|
||||
return res.status(200).json({ message: "Template saved successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async GetTemplate(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
const existingTemplate = await templateModel(organization)
|
||||
.find({
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
||||
if (!existingTemplate) return res.status(409).send([]);
|
||||
return res.status(200).json(existingTemplate);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,23 @@
|
||||
import { Request, Response } from "express";
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class widgetService {
|
||||
static async addWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const {
|
||||
organization,
|
||||
// panel,
|
||||
zoneId,
|
||||
widget,
|
||||
} = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
panelName: widget.panel,
|
||||
zoneId: zoneId,
|
||||
@@ -25,10 +33,35 @@ export class widgetService {
|
||||
isArchive: false,
|
||||
// widgetOrder: widget.widgetOrder,
|
||||
});
|
||||
// console.log('existingWidget: ', widget.data.measurements);
|
||||
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 res
|
||||
.status(409)
|
||||
.json({ message: "Widget already exist for the widgetID" });
|
||||
.status(200)
|
||||
.json({ message: "Widget updated successfully" });
|
||||
// return res
|
||||
// .status(409)
|
||||
// .json({ message: "Widget already exist for the widgetID" });
|
||||
}
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widget.id,
|
||||
@@ -39,7 +72,7 @@ export class widgetService {
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
// measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1hr",
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
});
|
||||
if (newWidget) {
|
||||
@@ -65,7 +98,7 @@ export class widgetService {
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget)
|
||||
return res.status(409).json({ message: "Widget already deleted" });
|
||||
return res.status(409).json({ message: "Widget not found" });
|
||||
const widgetData = await widgetSchema(organization).updateOne(
|
||||
{ _id: findWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
@@ -73,27 +106,24 @@ export class widgetService {
|
||||
|
||||
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 });
|
||||
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();
|
||||
}
|
||||
// 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)) {
|
||||
panelData.widgets = panelData.widgets.filter(
|
||||
(widget: any) => widget !== findWidget._id
|
||||
);
|
||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||
panelData.widgets.splice(index1, 1);
|
||||
}
|
||||
await panelData.save();
|
||||
}
|
||||
@@ -150,13 +180,13 @@ export class widgetService {
|
||||
try {
|
||||
const existingWidget = await widgetSchema(organization)
|
||||
.findOne({
|
||||
_id: widgetID,
|
||||
widgetID: widgetID,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("Data -_id");
|
||||
const Datastructure = {
|
||||
measurements: existingWidget.Data.measurements || {},
|
||||
duration: existingWidget.Data.duration || "1hr",
|
||||
duration: existingWidget.Data.duration || "1h",
|
||||
};
|
||||
|
||||
if (existingWidget) return res.status(200).json({ Data: Datastructure });
|
||||
|
||||
Reference in New Issue
Block a user