32 lines
899 B
JavaScript
32 lines
899 B
JavaScript
import {
|
|
createLocation,
|
|
getLocationByQuery,
|
|
getLocationByRadius,
|
|
} from "../models/Location/operations";
|
|
|
|
export const createLocationController = async (req, res) => {
|
|
try {
|
|
const { user } = res.locals;
|
|
const { location } = req.body;
|
|
const dbPayload = {
|
|
battery: location.battery.level,
|
|
coordinatess: location.coords,
|
|
recorded_at: location.recorded_at,
|
|
};
|
|
const uploaded = await createLocation({ ...dbPayload, user: user?.id });
|
|
console.log("BG LOCATION DB DOC", uploaded, user);
|
|
res.status(200).json({ result: uploaded });
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
};
|
|
|
|
export const getLocationController = async (req, res) => {
|
|
try {
|
|
const location = await getLocationByQuery(req.query);
|
|
res.status(200).json(location);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
};
|