Fix NaN values when importing from upstream

This commit is contained in:
Chrystian Huot 2020-09-03 09:03:56 -04:00
parent aa1c79ac22
commit 4606e8cbab
2 changed files with 23 additions and 14 deletions

View file

@ -73,9 +73,9 @@ class CallUpload {
frequencies = []; frequencies = [];
} }
const frequency = parseInt(reqBody.frequency, 10); const frequency = parseInt(reqBody.frequency, 10) || null;
const source = parseInt(reqBody.source, 10); const source = parseInt(reqBody.source, 10) || null;
let sources; let sources;
@ -86,16 +86,18 @@ class CallUpload {
sources = []; sources = [];
} }
const system = parseInt(reqBody.system, 10); const system = parseInt(reqBody.system, 10) || null;
const talkgroup = parseInt(reqBody.talkgroup, 10); const talkgroup = parseInt(reqBody.talkgroup, 10) || null;
if (!this.controller.validateApiKey(apiKey, system, talkgroup)) { if (!this.controller.validateApiKey(apiKey, system, talkgroup)) {
const message = `system=${system} talkgroup=${talkgroup} file=${audioName} No matching system/talkgroup`; const message = `system=${system} talkgroup=${talkgroup} file=${audioName} No matching system/talkgroup`;
console.warn(`Api: ${message}`); console.warn(`Api: ${message}`);
return res.send(`${message}\n`); res.send(`${message}\n`);
return;
} }
try { try {
@ -115,7 +117,7 @@ class CallUpload {
res.send(`Call imported successfully.\n`); res.send(`Call imported successfully.\n`);
} catch (error) { } catch (error) {
res.send(error.message); res.status(500).send(error.message);
} }
} }
}); });

View file

@ -404,10 +404,17 @@ class Controller extends EventEmitter {
} }
} }
const newCall = await this.models.call.create(call); let newCall;
try {
newCall = await this.models.call.create(call);
console.log(`NewCall: system=${call.system} talkgroup=${call.talkgroup} file=${call.audioName} Success`); console.log(`NewCall: system=${call.system} talkgroup=${call.talkgroup} file=${call.audioName} Success`);
} catch (error) {
console.log(`NewCall: system=${call.system} talkgroup=${call.talkgroup} file=${call.audioName} ${error.message}`);
}
this.emit('call', newCall); this.emit('call', newCall);
} }