nodes should be created and updated from map report packets

This commit is contained in:
liamcottle
2024-03-31 23:47:56 +13:00
parent cff5ed54cb
commit ec5607de12
3 changed files with 37 additions and 7 deletions

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `nodes` MODIFY `is_licensed` BOOLEAN NULL;

View File

@ -19,8 +19,8 @@ model Node {
long_name String
short_name String
hardware_model Int
is_licensed Boolean
role Int
is_licensed Boolean?
latitude Int?
longitude Int?

View File

@ -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