zone updates
This commit is contained in:
@@ -3,30 +3,33 @@ import zoneModel from "../../../shared/model/lines/zone-Model";
|
|||||||
export class zone {
|
export class zone {
|
||||||
static async setZone(req: Request, res: Response) {
|
static async setZone(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const {organization,userId,zoneData}=req.body
|
const { organization, userId, zoneData } = req.body
|
||||||
const zoneId =zoneData.zoneId
|
console.log('req.body: ', req.body);
|
||||||
const points =zoneData.points
|
const zoneId = zoneData.zoneId
|
||||||
const zoneName =zoneData.zoneName
|
const points = zoneData.points
|
||||||
const layer =zoneData.layer
|
const zoneName = zoneData.zoneName
|
||||||
const findZoneId= await zoneModel(organization).findOne({zoneId:zoneId})
|
const layer = zoneData.layer
|
||||||
|
const viewPortCenter = zoneData.viewPortCenter
|
||||||
|
const viewPortposition = zoneData.viewPortposition
|
||||||
|
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const updateZone= await zoneModel(organization).findOneAndUpdate(
|
const updateZone = await zoneModel(organization).findOneAndUpdate(
|
||||||
{zoneId:zoneId},{points:points},{new:true}
|
{ zoneId: zoneId }, { points: points, viewPortposition: viewPortposition, viewPortCenter: viewPortCenter }, { new: true }
|
||||||
).select("-_id -__v")
|
).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 {
|
} else {
|
||||||
const zoneCreate = await zoneModel(organization).create({
|
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)
|
const createdZone = await zoneModel(organization)
|
||||||
.findById(zoneCreate._id)
|
.findById(zoneCreate._id)
|
||||||
.select('-_id -__v')
|
.select('-_id -__v')
|
||||||
.lean();
|
.lean();
|
||||||
res.status(201).json({message: 'zone created', data: createdZone,organization:organization})
|
res.status(201).json({ message: 'zone created', data: createdZone, organization: organization })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', 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) {
|
static async deleteZone(req: Request, res: Response) {
|
||||||
@@ -56,7 +59,7 @@ export class zone {
|
|||||||
|
|
||||||
const findZoneId = await zoneModel(organization)
|
const findZoneId = await zoneModel(organization)
|
||||||
.find()
|
.find()
|
||||||
.select("zoneId zoneName layer points -_id");
|
.select("zoneId zoneName layer points viewPortCenter viewPortposition -_id");
|
||||||
|
|
||||||
if (!findZoneId) {
|
if (!findZoneId) {
|
||||||
res.status(500).json({ message: 'Invalid zone' })
|
res.status(500).json({ message: 'Invalid zone' })
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const MainModel = <T>(
|
|||||||
authSource: process.env.MONGO_AUTH_DB || 'admin', // Default to 'admin' if not provided
|
authSource: process.env.MONGO_AUTH_DB || 'admin', // Default to 'admin' if not provided
|
||||||
maxPoolSize: 50,
|
maxPoolSize: 50,
|
||||||
};
|
};
|
||||||
|
console.log('authOptions: ', authOptions);
|
||||||
// Check if the connection already exists
|
// Check if the connection already exists
|
||||||
if (connections[db]) {
|
if (connections[db]) {
|
||||||
return connections[db].model<T>(modelName, schema, collectionName);
|
return connections[db].model<T>(modelName, schema, collectionName);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export interface zoneSchema extends Document {
|
|||||||
createBy: mongoose.Types.ObjectId
|
createBy: mongoose.Types.ObjectId
|
||||||
points: []
|
points: []
|
||||||
layer: Number
|
layer: Number
|
||||||
|
viewPortCenter: []
|
||||||
|
viewPortposition: []
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +18,8 @@ const zoneSchema: Schema = new Schema({
|
|||||||
createBy: { type: Schema.Types.ObjectId, ref: "Users", },
|
createBy: { type: Schema.Types.ObjectId, ref: "Users", },
|
||||||
points: { type: Array },
|
points: { type: Array },
|
||||||
layer: { type: Number, required: true },
|
layer: { type: Number, required: true },
|
||||||
|
viewPortCenter: { type: Array, required: true },
|
||||||
|
viewPortposition: { type: Array, required: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,53 @@
|
|||||||
import zoneModel from "../../../shared/model/lines/zone-Model";
|
import zoneModel from "../../../shared/model/lines/zone-Model";
|
||||||
|
|
||||||
export const setZone = async (data:any)=>{
|
export const setZone = async (data: any) => {
|
||||||
try {
|
try {
|
||||||
const {organization,userId,zoneData}=data
|
const { organization, userId, zoneData } = data
|
||||||
const zoneId =zoneData.zoneId
|
console.log('data: ', data);
|
||||||
const points =zoneData.points
|
const zoneId = zoneData.zoneId
|
||||||
const zoneName =zoneData.zoneName
|
const points = zoneData.points
|
||||||
const layer =zoneData.layer
|
const zoneName = zoneData.zoneName
|
||||||
const findZoneId= await zoneModel(organization).findOne({zoneId:zoneId})
|
const layer = zoneData.layer
|
||||||
|
const viewPortCenter = zoneData.viewPortCenter
|
||||||
|
const viewPortposition = zoneData.viewPortposition
|
||||||
|
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const updateZone= await zoneModel(organization).findOneAndUpdate(
|
const updateZone = await zoneModel(organization).findOneAndUpdate(
|
||||||
{zoneId:zoneId},{points:points},{new:true}
|
{ zoneId: zoneId }, { points: points, viewPortposition: viewPortposition, viewPortCenter: viewPortCenter }, { new: true }
|
||||||
).select("-_id -__v")
|
).select("-_id -__v")
|
||||||
return { success: true, message: 'zone updated', data: updateZone,organization:organization}
|
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
const zoneCreate = await zoneModel(organization).create({
|
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)
|
const createdZone = await zoneModel(organization)
|
||||||
.findById(zoneCreate._id)
|
.findById(zoneCreate._id)
|
||||||
.select('-_id -__v')
|
.select('-_id -__v')
|
||||||
.lean();
|
.lean();
|
||||||
return { success: true, message: 'zone created', data: createdZone,organization:organization}
|
return { success: true, message: 'zone created', data: createdZone, organization: organization }
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', 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 {
|
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) {
|
if (findZoneId) {
|
||||||
const deleteZone= await zoneModel(organization).findOneAndDelete(
|
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
||||||
{zoneId:zoneId,createBy:userId}
|
{ zoneId: zoneId, createBy: userId }
|
||||||
).select("-_id -__v")
|
).select("-_id -__v")
|
||||||
return { success: true, message: 'zone deleted', data: deleteZone,organization:organization}
|
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return { success: true, message: 'Invalid zone ID',organization:organization}
|
return { success: true, message: 'Invalid zone ID', organization: organization }
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', 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