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' })

View File

@@ -19,6 +19,7 @@ const MainModel = <T>(
authSource: process.env.MONGO_AUTH_DB || 'admin', // Default to 'admin' if not provided
maxPoolSize: 50,
};
console.log('authOptions: ', authOptions);
// Check if the connection already exists
if (connections[db]) {
return connections[db].model<T>(modelName, schema, collectionName);

View File

@@ -6,6 +6,8 @@ export interface zoneSchema extends Document {
createBy: mongoose.Types.ObjectId
points: []
layer: Number
viewPortCenter: []
viewPortposition: []
}
@@ -16,6 +18,8 @@ const zoneSchema: Schema = new Schema({
createBy: { type: Schema.Types.ObjectId, ref: "Users", },
points: { type: Array },
layer: { type: Number, required: true },
viewPortCenter: { type: Array, required: true },
viewPortposition: { type: Array, required: true },
});

View File

@@ -1,50 +1,53 @@
import zoneModel from "../../../shared/model/lines/zone-Model";
export const setZone = async (data:any)=>{
export const setZone = async (data: any) => {
try {
const {organization,userId,zoneData}=data
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 } = data
console.log('data: ', data);
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}
).select("-_id -__v")
return { success: true, message: 'zone updated', data: updateZone,organization:organization}
const updateZone = await zoneModel(organization).findOneAndUpdate(
{ zoneId: zoneId }, { points: points, viewPortposition: viewPortposition, viewPortCenter: viewPortCenter }, { new: true }
).select("-_id -__v")
return { success: true, 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();
return { success: true, message: 'zone created', data: createdZone,organization:organization}
return { success: true, message: 'zone created', data: createdZone, organization: organization }
}
} catch (error) {
console.log('error: ', error);
return { success: false, message: 'Zone not found',error }
return { success: false, message: 'Zone not found', error }
}
}
export const deleteZone = async (data:any)=>{
export const deleteZone = async (data: any) => {
try {
const {organization,userId,zoneId}=data
const { organization, userId, zoneId } = data
const findZoneId= await zoneModel(organization).findOne({zoneId:zoneId})
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
if (findZoneId) {
const deleteZone= await zoneModel(organization).findOneAndDelete(
{zoneId:zoneId,createBy:userId}
const deleteZone = await zoneModel(organization).findOneAndDelete(
{ zoneId: zoneId, createBy: userId }
).select("-_id -__v")
return { success: true, message: 'zone deleted', data: deleteZone,organization:organization}
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
} else {
return { success: true, message: 'Invalid zone ID',organization:organization}
return { success: true, message: 'Invalid zone ID', organization: organization }
}
} catch (error) {
console.log('error: ', error);
return { success: false, message: 'Zone not found',error }
return { success: false, message: 'Zone not found', error }
}
}