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 { const organization = req.body.organization; console.log("organization: ", organization); const zoneDatas = req.body.zonesdata; console.log("zoneDatas: ", zoneDatas); try { const existingZone = await zoneSchema(organization).findOne({ _id: zoneDatas.zoneID, isArchive: false, }); if (!existingZone) { const newZone = await zoneSchema(organization).create({ zoneName: zoneDatas.zonename, // zoneUUID: zoneDatas.uuid, zonePoints: zoneDatas.points, centerPoints: zoneDatas.centerPoints, createdBy: zoneDatas.userid, sceneID: zoneDatas.sceneid, }); if (newZone) return res.send({ message: "Zone created successfully", zoneData: { zoneName: newZone.zoneName, points: newZone.zonePoints, centerPoints: newZone.centerPoints, }, }); } else { const replaceZone = await zoneSchema(organization).findOneAndUpdate( { _id: zoneDatas.zoneID, isArchive: false }, { zonePoints: zoneDatas.zonePoints, centerPoints: zoneDatas.centerPoints, }, { new: true } ); if (!replaceZone) return res.send({ message: "Zone not updated" }); else return res.send({ message: "updated successfully", zoneData: { zoneName: replaceZone.zoneName, points: replaceZone.zonePoints, centerPoints: replaceZone.centerPoints, }, }); } } catch (error: any) { return res.status(500).send(error.message); } } }