Insert into ReadingRepo, but it's not tested yet

This commit is contained in:
Starbeamrainbowlabs 2019-07-09 17:31:08 +01:00
parent 3123215f11
commit 855cbc0c1b
3 changed files with 16 additions and 5 deletions

View File

@ -11,12 +11,12 @@ class ReadingRepo {
this.query_insert = this.db.prepare(`INSERT INTO readings (
id,
lat, long,
data_rate_id, code_rate, bit_rate
data_rate, code_rate
) VALUES (
:id,
:latitude,
:longitude,
:data_rate_id, :code_rate, :bit_rate
:data_rate, :code_rate
)`);
this.insert_query.run(reading);

View File

@ -5,7 +5,7 @@ CREATE TABLE readings IF NOT EXISTS (
long FLOAT NOT NULL, -- Longitude component of GPS co-ordinates of reading,
data_rate TEXT NOT NULL, -- The id of the data rate code in the data_rates table that describes the data rate at which the message was transmitted
code_rate TEXT, -- The coding rate at which the message was transmitted. FUTURE: This may need to be an INTEGER field - not sure
bit_rate INTEGER, -- The bit rate at which the message was transmitted
-- bit_rate INTEGER, -- The bit rate at which the message was transmitted -- We didn't actually recieve this - disparity between API docs & actual message
);
CREATE TABLE rssis IF NOT EXISTS (
id INTEGER PRIMARY KEY, -- Random unique int

View File

@ -3,8 +3,10 @@
import { decode_payload } from './DecodePayload.mjs';
class MessageHandler {
constructor() {
constructor({ ReadingRepo, RSSIRepo, GatewayRepo }) {
this.repo_reading = ReadingRepo;
this.repo_rssi = RSSIRepo;
this.repo_gateway = GatewayRepo;
}
async handle(message) {
@ -12,6 +14,15 @@ class MessageHandler {
let decoded_payload = decode_payload(message.payload_raw);
console.log(decoded_payload);
this.repo_reading.add({
id: decoded_payload.id,
latitude: decoded_payload.latitude,
longitude: decoded_payload.longitude,
data_rate: message.metadata.data_rate,
code_rate: message.metadata.coding_rate
});
}
}