nodes should be created and updated from map report packets
This commit is contained in:
36
src/mqtt.js
36
src/mqtt.js
@ -603,10 +603,6 @@ client.on("message", async (topic, message) => {
|
||||
|
||||
else if(portnum === 73) {
|
||||
|
||||
if(!collectMapReports){
|
||||
return;
|
||||
}
|
||||
|
||||
const mapReport = MapReport.decode(envelope.packet.decoded.payload);
|
||||
|
||||
if(logKnownPacketTypes) {
|
||||
@ -616,6 +612,38 @@ client.on("message", async (topic, message) => {
|
||||
});
|
||||
}
|
||||
|
||||
// create or update node in db
|
||||
try {
|
||||
|
||||
// data to set on node
|
||||
const data = {
|
||||
long_name: mapReport.longName,
|
||||
short_name: mapReport.shortName,
|
||||
hardware_model: mapReport.hwModel,
|
||||
role: mapReport.role,
|
||||
latitude: mapReport.latitudeI,
|
||||
longitude: mapReport.longitudeI,
|
||||
altitude: mapReport.altitude !== 0 ? mapReport.altitude : null,
|
||||
};
|
||||
|
||||
await prisma.node.upsert({
|
||||
where: {
|
||||
node_id: envelope.packet.from,
|
||||
},
|
||||
create: {
|
||||
node_id: envelope.packet.from,
|
||||
...data,
|
||||
},
|
||||
update: data,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
if(!collectMapReports){
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// find an existing map with duplicate information created in the last 60 seconds
|
||||
|
Reference in New Issue
Block a user