Files
Dwinzo-Backend-V0.0/src/socket-server/services/lines/zone-controller.ts

51 lines
2.4 KiB
TypeScript
Raw Normal View History

import zoneModel from "../../../shared/model/builder/lines/zone-Model.ts";
2025-03-26 12:23:03 +05:30
export const setZone = async (data: any) => {
const { organization, userId, zoneData } = data
2025-03-18 17:46:24 +05:30
try {
2025-03-26 12:23:03 +05:30
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 })
2025-03-18 17:46:24 +05:30
if (findZoneId) {
2025-03-26 12:23:03 +05:30
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 }
2025-03-18 17:46:24 +05:30
} else {
const zoneCreate = await zoneModel(organization).create({
zoneId, createdBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
2025-03-18 17:46:24 +05:30
})
const createdZone = await zoneModel(organization)
.findById(zoneCreate._id)
.select('-_id -__v')
.lean();
2025-03-26 12:23:03 +05:30
return { success: true, message: 'zone created', data: createdZone, organization: organization }
2025-03-18 17:46:24 +05:30
}
} catch (error) {
console.log('error: ', error);
return { success: false, message: 'Zone not found', error , organization: organization}
2025-03-18 17:46:24 +05:30
}
}
2025-03-26 12:23:03 +05:30
export const deleteZone = async (data: any) => {
const { organization, userId, zoneId } = data
2025-03-18 17:46:24 +05:30
try {
2025-03-26 12:23:03 +05:30
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
2025-03-18 17:46:24 +05:30
if (findZoneId) {
2025-03-26 12:23:03 +05:30
const deleteZone = await zoneModel(organization).findOneAndDelete(
{ zoneId: zoneId, createdBy: userId }
2025-03-18 17:46:24 +05:30
).select("-_id -__v")
2025-03-26 12:23:03 +05:30
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
2025-03-18 17:46:24 +05:30
} else {
2025-03-26 12:23:03 +05:30
return { success: true, message: 'Invalid zone ID', organization: organization }
2025-03-18 17:46:24 +05:30
}
} catch (error) {
console.log('error: ', error);
return { success: false, message: 'Zone not found', error, organization: organization }
2025-03-18 17:46:24 +05:30
}
}