panel widget point service and model API completed
This commit is contained in:
@@ -9,15 +9,16 @@ export class Zoneservice {
|
||||
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneUUID: zoneDatas.zoneId,
|
||||
zoneId: zoneDatas.zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) {
|
||||
const newZone = await zoneSchema(organization).create({
|
||||
zoneName: zoneDatas.zonename,
|
||||
zoneUUID: zoneDatas.zoneId,
|
||||
zoneId: zoneDatas.zoneId,
|
||||
zonePoints: zoneDatas.points,
|
||||
centerPoints: zoneDatas.viewportPosition,
|
||||
viewPortposition: zoneDatas.viewportPosition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
createdBy: zoneDatas.userid,
|
||||
layer: zoneDatas.layer,
|
||||
sceneID: zoneDatas.sceneID,
|
||||
@@ -28,15 +29,17 @@ export class Zoneservice {
|
||||
zoneData: {
|
||||
zoneName: newZone.zoneName,
|
||||
points: newZone.zonePoints,
|
||||
centerPoints: newZone.centerPoints,
|
||||
viewPortposition: zoneDatas.viewPortposition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const replaceZone = await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneUUID: zoneDatas.zoneId, isArchive: false },
|
||||
{ zoneId: zoneDatas.zoneId, isArchive: false },
|
||||
{
|
||||
zonePoints: zoneDatas.points,
|
||||
centerPoints: zoneDatas.viewportPosition,
|
||||
viewPortposition: zoneDatas.viewPortposition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
@@ -48,7 +51,8 @@ export class Zoneservice {
|
||||
zoneData: {
|
||||
zoneName: replaceZone.zoneName,
|
||||
points: replaceZone.zonePoints,
|
||||
centerPoints: replaceZone.centerPoints,
|
||||
viewPortposition: replaceZone.viewPortposition,
|
||||
viewPortCenter: replaceZone.viewPortCenter,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -59,17 +63,17 @@ export class Zoneservice {
|
||||
|
||||
static async deleteAZone(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
const zoneUUID = req.params.zoneId;
|
||||
const zoneId = req.params.zoneId;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneUUID: zoneUUID,
|
||||
zoneId: zoneId,
|
||||
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 },
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
@@ -87,19 +91,21 @@ export class Zoneservice {
|
||||
|
||||
static async singleZonePanelDatas(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
const zoneID = req.params.zoneID;
|
||||
const zoneId = req.params.zoneId;
|
||||
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization)
|
||||
.findOne({
|
||||
_id: req.params.zoneID,
|
||||
zoneId: req.params.zoneId,
|
||||
isArchive: false,
|
||||
})
|
||||
.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,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
const zoneName = existingZone.zoneName as string;
|
||||
|
||||
@@ -107,6 +113,7 @@ export class Zoneservice {
|
||||
panelData.map(async (data) => {
|
||||
const widgetDataArray = await widgetSchema(organization).find({
|
||||
panelID: data._id,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
return widgetDataArray.map((widgetData) => ({
|
||||
@@ -130,7 +137,7 @@ export class Zoneservice {
|
||||
widgets: flattenedWidgets,
|
||||
};
|
||||
|
||||
return res.send(objectData);
|
||||
return res.status(200).json(objectData);
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
@@ -143,10 +150,10 @@ export class Zoneservice {
|
||||
try {
|
||||
const Allzones = await zoneSchema(organization)
|
||||
.find({ sceneID: sceneID, isArchive: false })
|
||||
.select("zoneName sceneID zoneUUID");
|
||||
.select("zoneName sceneID zoneId");
|
||||
|
||||
if (!Allzones || Allzones.length === 0) {
|
||||
return res.status(200).json({ message: "Zone not found for the UUID" });
|
||||
return res.status(404).json({ message: "Zone not found for the UUID" });
|
||||
}
|
||||
return res.status(200).json(Allzones);
|
||||
} catch (error: any) {
|
||||
@@ -158,25 +165,25 @@ export class Zoneservice {
|
||||
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);
|
||||
const zoneId = req.params.zoneId;
|
||||
console.log("zoneId: ", zoneId);
|
||||
const findZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
});
|
||||
// .select("zoneName");
|
||||
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> {
|
||||
// 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");
|
||||
// .select("zoneName sceneID zoneId");
|
||||
|
||||
// if (!Allzones || Allzones.length === 0) {
|
||||
// return res.send({ message: "Zone not found for the UUID" });
|
||||
|
||||
Reference in New Issue
Block a user