2025-03-25 12:34:01 +05:30
|
|
|
import { Request, Response } from "express";
|
|
|
|
|
import zoneSchema from "../../shared/model/builder/lines/zone-Model.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({
|
2025-03-25 17:24:42 +05:30
|
|
|
zoneUUID: zoneDatas.zoneId,
|
2025-03-25 12:34:01 +05:30
|
|
|
isArchive: false,
|
|
|
|
|
});
|
|
|
|
|
if (!existingZone) {
|
|
|
|
|
const newZone = await zoneSchema(organization).create({
|
|
|
|
|
zoneName: zoneDatas.zonename,
|
2025-03-25 17:24:42 +05:30
|
|
|
zoneUUID: zoneDatas.zoneId,
|
2025-03-25 12:34:01 +05:30
|
|
|
zonePoints: zoneDatas.points,
|
2025-03-25 17:24:42 +05:30
|
|
|
centerPoints: zoneDatas.viewportPosition,
|
2025-03-25 12:34:01 +05:30
|
|
|
createdBy: zoneDatas.userid,
|
2025-03-25 17:24:42 +05:30
|
|
|
layer: zoneDatas.layer,
|
|
|
|
|
sceneID: zoneDatas.sceneID || "scene123",
|
2025-03-25 12:34:01 +05:30
|
|
|
});
|
|
|
|
|
if (newZone)
|
2025-03-25 17:24:42 +05:30
|
|
|
return res.status(200).json({
|
2025-03-25 12:34:01 +05:30
|
|
|
message: "Zone created successfully",
|
|
|
|
|
zoneData: {
|
|
|
|
|
zoneName: newZone.zoneName,
|
|
|
|
|
points: newZone.zonePoints,
|
|
|
|
|
centerPoints: newZone.centerPoints,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const replaceZone = await zoneSchema(organization).findOneAndUpdate(
|
2025-03-25 17:24:42 +05:30
|
|
|
{ zoneUUID: zoneDatas.zoneId, isArchive: false },
|
2025-03-25 12:34:01 +05:30
|
|
|
{
|
2025-03-25 17:24:42 +05:30
|
|
|
zonePoints: zoneDatas.points,
|
|
|
|
|
centerPoints: zoneDatas.viewportPosition,
|
2025-03-25 12:34:01 +05:30
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
2025-03-25 17:24:42 +05:30
|
|
|
if (!replaceZone)
|
|
|
|
|
return res.status(404).json({ message: "Zone not updated" });
|
2025-03-25 12:34:01 +05:30
|
|
|
else
|
2025-03-25 17:24:42 +05:30
|
|
|
return res.status(200).json({
|
2025-03-25 12:34:01 +05:30
|
|
|
message: "updated successfully",
|
|
|
|
|
zoneData: {
|
|
|
|
|
zoneName: replaceZone.zoneName,
|
|
|
|
|
points: replaceZone.zonePoints,
|
|
|
|
|
centerPoints: replaceZone.centerPoints,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return res.status(500).send(error.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-25 17:24:42 +05:30
|
|
|
|
|
|
|
|
static async deleteAZone(req: Request, res: Response): Promise<any> {
|
|
|
|
|
const organization = req.query.organization;
|
|
|
|
|
const zoneUUID = req.params.zoneId;
|
|
|
|
|
try {
|
|
|
|
|
const existingZone = await zoneSchema(organization).findOne({
|
|
|
|
|
zoneUUID: zoneUUID,
|
|
|
|
|
isArchive: false,
|
|
|
|
|
});
|
|
|
|
|
if (!existingZone) {
|
|
|
|
|
return res.status(404).json({ message: "Zone not found for the UUID" });
|
|
|
|
|
} else {
|
|
|
|
|
const deleteZone = await zoneSchema(organization).findOneAndUpdate(
|
|
|
|
|
{ zoneUUID: zoneUUID, isArchive: false },
|
|
|
|
|
{
|
|
|
|
|
isArchive: true,
|
|
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (deleteZone) {
|
|
|
|
|
return res.status(200).json({ message: "Zone deleted successfully" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return res.status(500).send(error.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
|
|
// 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 || []),
|
|
|
|
|
// },
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
const sceneID = req.params.sceneID || "scene123";
|
|
|
|
|
try {
|
|
|
|
|
const Allzones = await zoneSchema(organization)
|
|
|
|
|
.find({ sceneID: sceneID, isArchive: false })
|
|
|
|
|
.select("zoneName sceneID zoneUUID");
|
|
|
|
|
|
|
|
|
|
if (!Allzones || Allzones.length === 0) {
|
|
|
|
|
return res.status(200).json({ message: "Zone not found for the UUID" });
|
|
|
|
|
}
|
|
|
|
|
return res.status(200).json(Allzones);
|
|
|
|
|
} 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;
|
|
|
|
|
// try {
|
|
|
|
|
// const Allzones = await zoneSchema(organization)
|
|
|
|
|
// .find({ sceneID: sceneID, isArchive: false })
|
|
|
|
|
// .select("zoneName sceneID zoneUUID");
|
|
|
|
|
|
|
|
|
|
// if (!Allzones || Allzones.length === 0) {
|
|
|
|
|
// return res.send({ message: "Zone not found for the UUID" });
|
|
|
|
|
// }
|
|
|
|
|
// return res.send(Allzones);
|
|
|
|
|
// } catch (error: any) {
|
|
|
|
|
// return res.status(500).send(error.message);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2025-03-25 12:34:01 +05:30
|
|
|
}
|