zone updates
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user