Operational Endpoints for Admin, Products, Assignments, Location, Vendor, Venue completed. Geofence Testing PEnding
This commit is contained in:
@@ -2,8 +2,10 @@ import {
|
||||
createAssignment,
|
||||
updateAssignment,
|
||||
getAssignmentsByQuery,
|
||||
aggregateAssignment,
|
||||
} from "../models/Assignment/operations.js";
|
||||
import dayjs from "dayjs";
|
||||
import { ObjectId } from "mongodb";
|
||||
|
||||
export const createAssignmentHandler = async (req, res) => {
|
||||
try {
|
||||
@@ -13,6 +15,7 @@ export const createAssignmentHandler = async (req, res) => {
|
||||
});
|
||||
const assignment = await createAssignment({
|
||||
...req.body,
|
||||
isActive: true,
|
||||
createdOn: dayjs().toISOString(),
|
||||
createdBy: user.id,
|
||||
});
|
||||
@@ -35,7 +38,41 @@ export const updateAssignmentHandler = async (req, res) => {
|
||||
export const getAssignmentsByUserHandler = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const assignment = await getAssignmentsByQuery({ user: id });
|
||||
const pipeline = [
|
||||
{
|
||||
$match: {
|
||||
user: ObjectId?.createFromHexString(id),
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "venues",
|
||||
localField: "venue",
|
||||
foreignField: "_id",
|
||||
as: "venue",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$venue",
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "partners",
|
||||
localField: "venue.entity",
|
||||
foreignField: "_id",
|
||||
as: "partner",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: "$partner",
|
||||
},
|
||||
},
|
||||
];
|
||||
const assignment = await aggregateAssignment(pipeline);
|
||||
res.status(200).json({ result: assignment });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Error getting assignment", error });
|
||||
|
||||
Reference in New Issue
Block a user