location controller updated with heading and created new models and controllers for remaining modules
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import {
|
||||
createVenue,
|
||||
getVenueById,
|
||||
getVenuesByQuery,
|
||||
getAllVenues,
|
||||
updateVenue,
|
||||
aggregateVenue,
|
||||
} from "../models/Venue/operations.js";
|
||||
import { coordinatesToGeoJson } from "../helpers/geoJson.helper.js";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export const createVenueController = async (req, res, next) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
|
||||
const { location } = req.body;
|
||||
|
||||
const geoJson = coordinatesToGeoJson({
|
||||
latitude: location.lat,
|
||||
longitude: location.lng,
|
||||
});
|
||||
const dbPayload = {
|
||||
...req.body,
|
||||
location: geoJson,
|
||||
createdBy: user.id,
|
||||
createdOn: dayjs().toISOString(),
|
||||
};
|
||||
|
||||
const venue = await createVenue(dbPayload);
|
||||
|
||||
res.status(200).json({ result: venue });
|
||||
} catch (error) {
|
||||
console.log("createVenueController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteVenueController = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const venue = await updateVenue(id, { isActive: false });
|
||||
|
||||
res.status(200).json({ result: venue });
|
||||
} catch (error) {
|
||||
console.log("deleteVenueController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getVenuesByEntityController = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const venues = await getVenuesByQuery({ entity: id });
|
||||
res.status(200).json({ result: venues });
|
||||
} catch (error) {
|
||||
console.log("getVenuesByEntity Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getVenueController = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const venue = await getVenueById(id);
|
||||
res.status(200).json({ result: venue });
|
||||
} catch (error) {
|
||||
console.log("getVenueController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user