refactor: only search once for wifiMessage
This commit is contained in:
parent
52d521a6ad
commit
39c07fcef0
@ -56,24 +56,24 @@ router.post(
|
||||
timestamp: latitudeData?.timestamp
|
||||
? new Date(latitudeData.timestamp)
|
||||
: longitudeData?.timestamp
|
||||
? new Date(longitudeData.timestamp)
|
||||
: undefined,
|
||||
? new Date(longitudeData.timestamp)
|
||||
: undefined,
|
||||
};
|
||||
const wifiTimestamp = (() => {
|
||||
const messages = message.uplink_message.decoded_payload?.messages?.[0];
|
||||
const wifiScan = messages?.find((e: { type: string }) => e.type === "Wi-Fi Scan");
|
||||
return wifiScan?.timestamp ? new Date(wifiScan.timestamp) : undefined;
|
||||
})();
|
||||
|
||||
const wifiMessage =
|
||||
message.uplink_message.decoded_payload?.messages[0].find(
|
||||
(e) => e.type === "Wi-Fi Scan"
|
||||
);
|
||||
|
||||
const wifiScans =
|
||||
message.uplink_message.decoded_payload?.messages[0]
|
||||
.find((e) => e.type === "Wi-Fi Scan")
|
||||
?.measurementValue?.map((w) => ({
|
||||
lp_ttn_end_device_uplinks_id,
|
||||
mac: w.mac,
|
||||
rssi: w.rssi,
|
||||
scanned_at_utc: wifiTimestamp,
|
||||
})) ?? [];
|
||||
wifiMessage?.measurementValue?.map((w) => ({
|
||||
lp_ttn_end_device_uplinks_id,
|
||||
mac: w.mac,
|
||||
rssi: w.rssi,
|
||||
scanned_at_utc: wifiMessage?.timestamp
|
||||
? new Date(wifiMessage.timestamp)
|
||||
: undefined,
|
||||
})) ?? [];
|
||||
|
||||
const ttnGatewayReceptions = message.uplink_message.rx_metadata.map(
|
||||
(g) => ({
|
||||
@ -109,9 +109,9 @@ router.post(
|
||||
gnss:
|
||||
gnnsLocation.latitude && gnnsLocation.longitude
|
||||
? {
|
||||
latitude: gnnsLocation.latitude,
|
||||
longitude: gnnsLocation.longitude,
|
||||
}
|
||||
latitude: gnnsLocation.latitude,
|
||||
longitude: gnnsLocation.longitude,
|
||||
}
|
||||
: undefined,
|
||||
gnss_timestamp: gnssTimestamp.timestamp,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user