Operational Endpoints for Admin, Products, Assignments, Location, Vendor, Venue completed. Geofence Testing PEnding
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import dayjs from "dayjs";
|
||||
import {
|
||||
createVendor,
|
||||
updateVendor,
|
||||
deleteVendor,
|
||||
getVendorsByQuery,
|
||||
getVendorById,
|
||||
getAllVendors,
|
||||
} from "../models/Vendor/operations";
|
||||
|
||||
export const createVendorController = async (req, res, next) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const vendor = await createVendor({
|
||||
...req.body,
|
||||
createdBy: user?.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
});
|
||||
res.status(201).json({ result: vendor });
|
||||
} catch (error) {
|
||||
console.log("createVendorController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const updateVendorController = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const vendor = await updateVendor(id, req.body);
|
||||
res.status(200).json({ result: vendor });
|
||||
} catch (error) {
|
||||
console.log("updateVendorController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getActiveVendorsController = async (req, res, next) => {
|
||||
try {
|
||||
const vendors = await getVendorsByQuery({ isActive: true });
|
||||
res.status(200).json({ result: vendors });
|
||||
} catch (error) {
|
||||
console.log("getActiveVendorsController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllVendorsController = async (req, res, next) => {
|
||||
try {
|
||||
const vendors = await getAllVendors();
|
||||
res.status(200).json({ result: vendors });
|
||||
} catch (error) {
|
||||
console.log("getAllVendorsController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const deactivateVendorController = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deactivatedVendor = await updateVendor(id, { isActive: false });
|
||||
res.status(200).json({ result: deactivatedVendor });
|
||||
} catch (error) {
|
||||
console.log("deactivateVendorController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getVendorByIdController = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const vendor = await getVendorById(id);
|
||||
|
||||
res.status(200).json({ result: vendor });
|
||||
} catch (error) {
|
||||
console.log("getVendorByIdController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user