panel widget point service and model API completed

This commit is contained in:
2025-03-28 09:46:30 +05:30
parent 15688d17c5
commit 7bb7fbced2
24 changed files with 1628 additions and 123 deletions

View File

@@ -1,15 +1,17 @@
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 panelService {
static async AddPanel(req: Request, res: Response): Promise<any> {
try {
const organization = req.body.organization;
const zoneID = req.body.zoneID;
const zoneId = req.body.zoneId;
const panelName = req.body.panelName;
const panelOrder = req.body.panelOrder;
const findZone = await zoneSchema(organization).findOne({
_id: zoneID,
zoneId: zoneId,
isArchive: false,
});
@@ -17,12 +19,12 @@ export class panelService {
return res.status(404).json({ message: "Zone not found" });
}
const updatezone = await zoneSchema(organization).findOneAndUpdate(
{ _id: findZone._id, isArchive: false },
{ zoneId: zoneId, isArchive: false },
{ panelOrder: panelOrder },
{ new: true }
);
const existingPanels = await panelSchema(organization).find({
zoneID: zoneID,
zoneId: zoneId,
isArchive: false,
});
@@ -37,7 +39,7 @@ export class panelService {
const createdPanels = [];
for (const panelName of missingPanels) {
const newPanel = await panelSchema(organization).create({
zoneID: zoneID,
zoneId: zoneId,
panelName: panelName,
widgets: [],
isArchive: false,
@@ -64,6 +66,43 @@ export class panelService {
}
static async deletePanel(req: Request, res: Response): Promise<any> {
try {
const { organization, panelID, zoneId } = 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({
zoneId: zoneId,
_id: panelID,
isArchive: false,
});
if (!existingPanel)
return res.status(409).json({ message: "Panel Already Deleted" });
const updatePanel = await panelSchema(organization).updateOne(
{ _id: panelID, isArchive: false },
{ $set: { isArchive: true } }
);
const existingWidgets = await widgetSchema(organization).find({
panelID: panelID,
isArchive: false,
});
for (const widgetData of existingWidgets) {
widgetData.isArchive = true;
await widgetData.save();
}
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
existingZone.panelOrder = existingZone.panelOrder.filter(
(panel: any) => panel !== existingPanel.panelName
);
await existingZone.save();
}
return res.status(200).json({ message: "Panel deleted successfully" });
} catch (error: any) {
return res.status(500).send(error.message);
}