location update with separate data structure for geofence events

This commit is contained in:
Shibi Chakkaravarthy
2026-06-16 00:56:15 +05:30
parent 36e1bf664f
commit 3ae41a8cd5
5 changed files with 158 additions and 5 deletions
+50 -1
View File
@@ -40,12 +40,49 @@ Sample Location Payload
"odometer_error": 0,
"odometer": 0
}
Geofence Event {
event: 'geofence',
is_moving: true,
uuid: 'dfa0f17d-017f-4fd1-beca-67e62f0087d9',
timestamp: '2026-06-15T18:15:08.430Z',
recorded_at: '2026-06-15T18:15:08.607Z',
age: 0.179,
odometer: 345.61,
odometer_error: 16.68,
coords: {
latitude: 13.1243472,
longitude: 80.1428553,
accuracy: 3.45,
speed: 1.01,
speed_accuracy: 0.19,
heading: 280.72,
heading_accuracy: 12.79,
altitude: -51.9,
ellipsoidal_altitude: -51.9,
altitude_accuracy: 1.11
},
activity: { type: 'walking', confidence: 100 },
battery: { is_charging: false, level: 0.69 },
geofence: {
identifier: '6a2e128af72b4c6184fd53ea-6a1f658f8fc61da8a1809091-6a2e126bf72b4c6184fd5310',
action: 'EXIT',
timestamp: '2026-06-15T18:15:08.612Z',
extras: {
venue: '6a2e126bf72b4c6184fd5310',
partner: '6a1f658f8fc61da8a1809091'
}
},
extras: {}
*/
export const createLocationController = async (req, res) => {
try {
const { user } = res.locals;
const { location } = req.body;
if (location.event === "geofence") {
console.log("Geofence Event", location);
}
const dbPayload = {
battery: location.battery.level,
coordinates: location.coords,
@@ -54,8 +91,20 @@ export const createLocationController = async (req, res) => {
activity: location?.activity?.type,
recorded_at: location.recorded_at,
};
if (location.event === "geofence") {
const [assignment, partner, venue] =
location?.geofence?.identifier?.split("-");
const geofencePayload = {
assignment,
partner,
venue,
action: location?.geofence?.action,
};
dbPayload.geofence = geofencePayload;
}
const uploaded = await createLocation({ ...dbPayload, user: user?.id });
console.log("BG LOCATION DB DOC", uploaded, user);
res.status(200).json({ result: uploaded });
} catch (error) {
console.log("createLocationController Error", error);