Operational Endpoints for Admin, Products, Assignments, Location, Vendor, Venue completed. Geofence Testing PEnding
This commit is contained in:
@@ -6,6 +6,8 @@ import {
|
||||
updateVenue,
|
||||
aggregateVenue,
|
||||
} from "../models/Venue/operations.js";
|
||||
import { ObjectId } from "mongodb";
|
||||
import { aggregateAssignment } from "../models/Assignment/operations.js";
|
||||
import { coordinatesToGeoJson } from "../helpers/geoJson.helper.js";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
@@ -69,3 +71,106 @@ export const getVenueController = async (req, res, next) => {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getAssignedVenuesController = async (req, res, next) => {
|
||||
try {
|
||||
const { userId } = req.params;
|
||||
// const { user } = res.locals;
|
||||
|
||||
const assignedVenues = await aggregateAssignment([
|
||||
{
|
||||
$match: {
|
||||
user: ObjectId.createFromHexString(userId),
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$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,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
res.status(200).json({ result: assignedVenues });
|
||||
} catch (error) {
|
||||
console.log("getAssignedVenues Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getUnassignedVenuesController = async (req, res, next) => {
|
||||
try {
|
||||
const unassignedVenues = await aggregateVenue([
|
||||
{
|
||||
$match: {
|
||||
category: "PARTNER"
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "assignments",
|
||||
localField: "_id",
|
||||
foreignField: "venue",
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
as: "activeAssignments",
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$or: [
|
||||
{ activeAssignments: { $size: 0 } },
|
||||
{ activeAssignments: { $exists: false } },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "partners",
|
||||
localField: "entity",
|
||||
foreignField: "_id",
|
||||
as: "partner",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$partner",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
res.status(200).json({ result: unassignedVenues });
|
||||
} catch (error) {
|
||||
console.log("getUnassignedVenuesController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user