widget panel Create and get operations completed
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneSchema from "../../shared/model/builder/lines/zone-Model.ts";
|
||||
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;
|
||||
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneUUID: zoneDatas.zoneId,
|
||||
@@ -17,7 +20,7 @@ export class Zoneservice {
|
||||
centerPoints: zoneDatas.viewportPosition,
|
||||
createdBy: zoneDatas.userid,
|
||||
layer: zoneDatas.layer,
|
||||
sceneID: zoneDatas.sceneID || "scene123",
|
||||
sceneID: zoneDatas.sceneID,
|
||||
});
|
||||
if (newZone)
|
||||
return res.status(200).json({
|
||||
@@ -82,47 +85,57 @@ export class Zoneservice {
|
||||
}
|
||||
}
|
||||
|
||||
// static async singleZone(req: Request, res: Response): Promise<any> {
|
||||
// const organization = req.query.organization;
|
||||
// console.log("organization: ", organization);
|
||||
// const zoneUUID = req.params.zoneUUID;
|
||||
// console.log("zoneUUID: ", zoneUUID);
|
||||
// try {
|
||||
// const existingZone = await zoneSchema(organization)
|
||||
// .findOne({
|
||||
// zoneUUID: req.params.zoneUUID,
|
||||
// })
|
||||
// // .select("-_id -__v -isArchive -createdAt -updatedAt");
|
||||
// console.log("existingZone: ", existingZone);
|
||||
// if (!existingZone) {
|
||||
// return res.send({ message: "Zone not found for the UUID" });
|
||||
// } else {
|
||||
// const panelData = await panelSchema(organization)
|
||||
// .find({
|
||||
// zoneUUID: zoneUUID,
|
||||
// })
|
||||
// .select("panelOriginalOrder panelSide lockedPanel");
|
||||
static async singleZonePanelDatas(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
const zoneID = req.params.zoneID;
|
||||
|
||||
// const zoneName = existingZone.zoneName as string;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization)
|
||||
.findOne({
|
||||
_id: req.params.zoneID,
|
||||
})
|
||||
.select("panelOrder zoneName zonePoints lockedPanel");
|
||||
if (!existingZone) {
|
||||
return res.send({ message: "Zone not found for the UUID" });
|
||||
} else {
|
||||
const panelData = await panelSchema(organization).find({
|
||||
zoneID: zoneID,
|
||||
});
|
||||
const zoneName = existingZone.zoneName as string;
|
||||
|
||||
// const objectData = {
|
||||
// [zoneName]: {
|
||||
// activeSides: panelData.flatMap((data) => data.panelSide || []),
|
||||
// lockedPanels: panelData.flatMap((data) => data.lockedPanel || []),
|
||||
// panelOrder: panelData.flatMap(
|
||||
// (data) => data.panelOriginalOrder || []
|
||||
// ),
|
||||
// points: existingZone.zonePoints || [],
|
||||
// widgets: panelData.flatMap((data) => data.widgets || []),
|
||||
// },
|
||||
// };
|
||||
const widgets = await Promise.all(
|
||||
panelData.map(async (data) => {
|
||||
const widgetDataArray = await widgetSchema(organization).find({
|
||||
panelID: data._id,
|
||||
});
|
||||
|
||||
// return res.send(objectData);
|
||||
// }
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
return widgetDataArray.map((widgetData) => ({
|
||||
id: widgetData.widgetID,
|
||||
type: widgetData.elementType,
|
||||
title: widgetData.widgetName,
|
||||
panel: widgetData.widgetside,
|
||||
data: widgetData.Data || [],
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
const flattenedWidgets = widgets.flat();
|
||||
|
||||
const objectData = {
|
||||
zoneName,
|
||||
activeSides: existingZone.panelOrder || [],
|
||||
panelOrder: existingZone.panelOrder || [],
|
||||
lockedPanels: existingZone.lockedPanel || [],
|
||||
points: existingZone.zonePoints || [],
|
||||
widgets: flattenedWidgets,
|
||||
};
|
||||
|
||||
return res.send(objectData);
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async allZones(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
@@ -141,6 +154,22 @@ export class Zoneservice {
|
||||
}
|
||||
}
|
||||
|
||||
static async ZoneData(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.query.organization;
|
||||
console.log("organization: ", organization);
|
||||
const zoneID = req.params.zoneID;
|
||||
console.log("zoneID: ", zoneID);
|
||||
const findZone = await zoneSchema(organization)
|
||||
.findOne({ _id: zoneID })
|
||||
// .select("zoneName");
|
||||
console.log("findZone: ", findZone);
|
||||
if (findZone) return res.status(200).json(findZone);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// static async ZoneIDgenerate(req: Request, res: Response): Promise<any> {
|
||||
// const organization = req.query.organization;
|
||||
// const sceneID = req.params.sceneID;
|
||||
|
||||
Reference in New Issue
Block a user