From 908ded08a7cce0f9e8f6ae86b5ad3f37581233b3 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 15 Jan 2023 20:09:00 +0000 Subject: [PATCH] Frontend: Add API Call for find-code Signed-off-by: Fred Boniface --- static/js/find-code.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/static/js/find-code.js b/static/js/find-code.js index dff065d..524193f 100644 --- a/static/js/find-code.js +++ b/static/js/find-code.js @@ -27,7 +27,7 @@ async function parseData(values){ getData("tiploc", values.tiploc) } else if (values.stanox != ""){ getData("stanox", values.stanox) - } else if (values.station != ""){ + } else if (values.name != ""){ getData("name", values.name) } else { errorNoData() @@ -36,8 +36,22 @@ async function parseData(values){ async function getData(type, value){ console.log(`Looking for: ${type} ${value}`) + try { + var url = `${window.location.origin}/api/v1/${type}/${value}`; + var resp = await fetch(url); + console.log(`Response: ${resp.json}`) + return await resp.json() + } catch (err) { + errorFetch(err) + } } async function errorNoData(){ + console.log("No data entered") window.alert("You haven't entered any data") +} + +async function errorFetch(err){ + console.log("Error fetching data") + console.log(err) } \ No newline at end of file