@adventurelabs/scout-core 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/tags.js +47 -8
- package/package.json +1 -1
package/dist/helpers/tags.js
CHANGED
|
@@ -164,25 +164,64 @@ export async function get_event_and_tags_by_event_id(event_id) {
|
|
|
164
164
|
data: null,
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
|
-
if (!data
|
|
167
|
+
if (!data || data.length === 0) {
|
|
168
168
|
return {
|
|
169
169
|
status: EnumWebResponse.ERROR,
|
|
170
170
|
msg: "Event not found",
|
|
171
171
|
data: null,
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
|
-
//
|
|
174
|
+
// Debug the location data structure
|
|
175
|
+
console.log("Raw event data from DB:", {
|
|
176
|
+
eventId: data[0].id,
|
|
177
|
+
location: data[0].location,
|
|
178
|
+
locationType: typeof data[0].location,
|
|
179
|
+
hasCoordinates: data[0].location &&
|
|
180
|
+
typeof data[0].location === "object" &&
|
|
181
|
+
"coordinates" in data[0].location,
|
|
182
|
+
});
|
|
183
|
+
// Transform location to latitude/longitude with better error handling
|
|
184
|
+
let latitude = null;
|
|
185
|
+
let longitude = null;
|
|
186
|
+
try {
|
|
187
|
+
if (data[0].location) {
|
|
188
|
+
if (typeof data[0].location === "object" && data[0].location !== null) {
|
|
189
|
+
// Handle PostGIS Point format: { coordinates: [lon, lat] }
|
|
190
|
+
if ("coordinates" in data[0].location &&
|
|
191
|
+
Array.isArray(data[0].location.coordinates)) {
|
|
192
|
+
longitude = data[0].location.coordinates[0];
|
|
193
|
+
latitude = data[0].location.coordinates[1];
|
|
194
|
+
}
|
|
195
|
+
// Handle alternative format: { x: lon, y: lat }
|
|
196
|
+
else if ("x" in data[0].location && "y" in data[0].location) {
|
|
197
|
+
longitude = data[0].location.x;
|
|
198
|
+
latitude = data[0].location.y;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Handle string format: "Point(lon lat)"
|
|
202
|
+
else if (typeof data[0].location === "string") {
|
|
203
|
+
const match = data[0].location.match(/Point\(([^)]+)\)/);
|
|
204
|
+
if (match) {
|
|
205
|
+
const coords = match[1].split(" ").map(Number);
|
|
206
|
+
if (coords.length === 2) {
|
|
207
|
+
longitude = coords[0];
|
|
208
|
+
latitude = coords[1];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (locationError) {
|
|
215
|
+
console.warn("Error parsing location data:", locationError);
|
|
216
|
+
// Continue with null coordinates
|
|
217
|
+
}
|
|
175
218
|
const transformedData = {
|
|
176
219
|
id: data[0].id,
|
|
177
220
|
inserted_at: data[0].inserted_at,
|
|
178
221
|
message: data[0].message,
|
|
179
222
|
media_url: data[0].media_url,
|
|
180
|
-
latitude:
|
|
181
|
-
|
|
182
|
-
: null,
|
|
183
|
-
longitude: data[0].location
|
|
184
|
-
? data[0].location.coordinates[0]
|
|
185
|
-
: null,
|
|
223
|
+
latitude: latitude,
|
|
224
|
+
longitude: longitude,
|
|
186
225
|
altitude: data[0].altitude,
|
|
187
226
|
heading: data[0].heading,
|
|
188
227
|
media_type: data[0].media_type,
|