Skip to content

Commit 7635e9d

Browse files
committed
[service] fix device id null reference in geopackage and csv exports
1 parent 5ef8375 commit 7635e9d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

service/src/export/csv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ export class Csv extends Exporter {
245245
if (!cache.user || cache.user._id.toString() !== location.userId.toString()) {
246246
cache.user = await User.getUserById(location.userId)
247247
}
248-
if (!cache.device || cache.device._id.toString() !== flat.deviceId.toString()) {
249-
cache.device = await Device.getDeviceById(flat.deviceId)
248+
if (!cache.device || cache.device._id.toString() !== flat.deviceId?.toString()) {
249+
cache.device = flat.deviceId ? await Device.getDeviceById(flat.deviceId) : undefined
250250
}
251251
if (cache.user) {
252252
flat.user = cache.user.username

service/src/export/geopackage.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,15 @@ export class GeoPackage extends Exporter {
232232
zoomToEnvelope = calculateBounds(location.geometry, zoomToEnvelope);
233233
userLastLocation = location;
234234

235+
const properties = location.properties || {}
235236
const feature: geojson.Feature<geojson.Point, any> = {
236237
type: 'Feature',
237238
geometry: location.geometry,
238-
properties: location.properties
239+
properties
239240
};
240-
feature.properties.mageId = location._id.toString();
241-
feature.properties.userId = location.userId.toString();
242-
feature.properties.deviceId = location.properties.deviceId.toString();
241+
feature.properties.mageId = location._id.toString()
242+
feature.properties.userId = location.userId?.toString()
243+
feature.properties.deviceId = properties.deviceId ? properties.deviceId.toString() : undefined
243244

244245
if (feature.properties.id) {
245246
delete feature.properties.id;

0 commit comments

Comments
 (0)