zone updates

This commit is contained in:
2025-03-26 12:23:03 +05:30
parent 723cdf8dc5
commit 679f16244f
4 changed files with 49 additions and 38 deletions

View File

@@ -3,30 +3,33 @@ import zoneModel from "../../../shared/model/lines/zone-Model";
export class zone {
static async setZone(req: Request, res: Response) {
try {
const {organization,userId,zoneData}=req.body
const zoneId =zoneData.zoneId
const points =zoneData.points
const zoneName =zoneData.zoneName
const layer =zoneData.layer
const findZoneId= await zoneModel(organization).findOne({zoneId:zoneId})
const { organization, userId, zoneData } = req.body
console.log('req.body: ', req.body);
const zoneId = zoneData.zoneId
const points = zoneData.points
const zoneName = zoneData.zoneName
const layer = zoneData.layer
const viewPortCenter = zoneData.viewPortCenter
const viewPortposition = zoneData.viewPortposition
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
if (findZoneId) {
const updateZone= await zoneModel(organization).findOneAndUpdate(
{zoneId:zoneId},{points:points},{new:true}
const updateZone = await zoneModel(organization).findOneAndUpdate(
{ zoneId: zoneId }, { points: points, viewPortposition: viewPortposition, viewPortCenter: viewPortCenter }, { new: true }
).select("-_id -__v")
res.status(201).json({message: 'zone updated', data: updateZone,organization:organization})
res.status(201).json({ message: 'zone updated', data: updateZone, organization: organization })
} else {
const zoneCreate = await zoneModel(organization).create({
zoneId,createBy:userId,zoneName:zoneName,points,layer
zoneId, createBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
})
const createdZone = await zoneModel(organization)
.findById(zoneCreate._id)
.select('-_id -__v')
.lean();
res.status(201).json({message: 'zone created', data: createdZone,organization:organization})
.findById(zoneCreate._id)
.select('-_id -__v')
.lean();
res.status(201).json({ message: 'zone created', data: createdZone, organization: organization })
}
} catch (error) {
console.log('error: ', error);
res.status(500).json({ message: 'Zone not found',error })
res.status(500).json({ message: 'Zone not found', error })
}
}
static async deleteZone(req: Request, res: Response) {
@@ -56,7 +59,7 @@ export class zone {
const findZoneId = await zoneModel(organization)
.find()
.select("zoneId zoneName layer points -_id");
.select("zoneId zoneName layer points viewPortCenter viewPortposition -_id");
if (!findZoneId) {
res.status(500).json({ message: 'Invalid zone' })