location update with separate data structure for geofence events
This commit is contained in:
@@ -98,3 +98,51 @@ export const getAssignmentByVenueHandler = async (req, res) => {
|
||||
res.status(500).json({ message: "Error getting assignment", error });
|
||||
}
|
||||
};
|
||||
|
||||
export const getAssignmentByIdHandler = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const pipeline = [
|
||||
{
|
||||
$match: {
|
||||
_id: ObjectId.createFromHexString(id),
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "venues",
|
||||
localField: "venue",
|
||||
foreignField: "_id",
|
||||
as: "venue",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$venue",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "partners",
|
||||
localField: "venue.entity",
|
||||
foreignField: "_id",
|
||||
as: "partner",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$partner",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const assignment = await aggregateAssignment(pipeline)[0];
|
||||
|
||||
res.status(200).json({ result: assignment });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error getting assignment", error });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user