From fbfdfaec51be5a7ead56a2888e4864c8b3470db5 Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Mon, 6 Dec 2021 14:59:09 +0200 Subject: Added a possibility to choose the weekday --- server.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index 86ed81e..6274ba2 100644 --- a/server.js +++ b/server.js @@ -80,11 +80,14 @@ async function buildMain(args) const DB = args["db"]; const data = await openFile(path); - const data_string = data.toString("utf-8"); - let res; + let data_string = data.toString("utf-8"); + let res; const d = new Date(); - const day = d.getDay(); + let day = d.getDay(); + + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 7)) + day = parseInt(query.day); if ((day === 0) || (day === 6)) res = `Maanantain ruoka: ${parse.get(day, query.index, DB)}`; @@ -95,7 +98,10 @@ async function buildMain(args) if (res === -1) res = "Kyseiselle kurssille/opettajalle ei löydy ruokailua päivältä!"; - return data_string.replace("\\(result\\)", res); + data_string = data_string.replace("\\(result\\)", res); + data_string = data_string.replace(`