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