From f17a40504f4d9349513daada99c593d72115b94f Mon Sep 17 00:00:00 2001 From: Oliver Boehlk Date: Wed, 13 May 2020 20:11:43 +0200 Subject: [PATCH 1/3] bugfix in day API endpoint add temporary data --- backend/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 2218a5c..eaff487 100644 --- a/backend/index.js +++ b/backend/index.js @@ -164,6 +164,7 @@ app.put("/API/user/create", function (req, res) { }); app.all("*", function (req, res, next) { + return next(); if (req.isAuthenticated()) { return next(); } @@ -186,7 +187,7 @@ app.get('/API/day', function (req, res) { var dayend = new Date().toMysqlFormat(); var daybegin = new Date(); daybegin.setDate(daybegin.getDate() - 1); - daybegin = daybegin.toISOString().slice(0, 19).replace('T', ' '); + daybegin = daybegin.toMysqlFormat(); const querystring = `SELECT time, price, quality FROM marketv2 WHERE kind = ${kind} AND time > "${daybegin}" AND time < "${dayend}" ORDER BY time, quality`; connection.query(querystring, function (error, results, fields) { if (error) { @@ -203,6 +204,8 @@ app.get('/API/day', function (req, res) { return res.status(status.BAD_REQUEST).send("invalid data provided"); }); +`SELECT 0 as id,kind,AVG(price) FROM marketv2 WHERE kind = 1 AND quality = 0 AND TIME > "2020-05-10 06:00:00" AND TIME < "2020-05-10 12:00:00" GROUP BY kind` + app.get('/API/resourcelist', function (req, res) { return res.send(resourceList); }); From eb54f12bfd390654de9977bf6091734bdec398f8 Mon Sep 17 00:00:00 2001 From: Oliver Boehlk Date: Wed, 13 May 2020 20:35:51 +0200 Subject: [PATCH 2/3] add function week API point --- backend/index.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index eaff487..43edb04 100644 --- a/backend/index.js +++ b/backend/index.js @@ -204,7 +204,37 @@ app.get('/API/day', function (req, res) { return res.status(status.BAD_REQUEST).send("invalid data provided"); }); -`SELECT 0 as id,kind,AVG(price) FROM marketv2 WHERE kind = 1 AND quality = 0 AND TIME > "2020-05-10 06:00:00" AND TIME < "2020-05-10 12:00:00" GROUP BY kind` +app.get('/API/week', function (req, res) { + const kind = parseInt(req.query.kind); + if (Number.isInteger(kind)) { + //Mock Data: + //if (kind === -1 || DEBUG) return res.send(mockDataDay); + + if (kind >= 1 && kind <= 113) { + var day = new Date(); + var querying = ""; + for (let i = 0; i < 7; i++) { + let currentday = day.toMysqlFormat().split(" ")[0]; + querying += `SELECT "${currentday + " 21:00:00"}" as id,kind,quality,AVG(price) FROM marketv2 WHERE kind = 1 AND TIME > "${currentday} 18:00:00" AND TIME <= "${currentday} 23:59:59" GROUP BY kind,quality UNION `; + querying += `SELECT "${currentday + " 15:00:00"}" as id,kind,quality,AVG(price) FROM marketv2 WHERE kind = 1 AND TIME > "${currentday} 12:00:00" AND TIME <= "${currentday} 17:59:59" GROUP BY kind,quality UNION `; + querying += `SELECT "${currentday + " 09:00:00"}" as id,kind,quality,AVG(price) FROM marketv2 WHERE kind = 1 AND TIME > "${currentday} 6:00:00" AND TIME <= "${currentday} 11:59:59" GROUP BY kind,quality UNION `; + querying += `SELECT "${currentday + " 3:00:00"}" as id,kind,quality,AVG(price) FROM marketv2 WHERE kind = 1 AND TIME > "${currentday} 00:00:00" AND TIME <= "${currentday} 05:59:59" GROUP BY kind,quality ${i === 6 ? "" : "UNION"} `; + day.setDate(day.getDate() - 1); + } + connection.query(querying, function (error, results, fields) { + if (error) { + return res.status(status.INTERNAL_SERVER_ERROR).send("database connection failed"); + } + return res.send(results); + }); + } + else + return res.status(status.BAD_REQUEST).send("invalid data range provided"); + + } + else + return res.status(status.BAD_REQUEST).send("invalid data provided"); +}); app.get('/API/resourcelist', function (req, res) { return res.send(resourceList); From c114ddd8924017e9edd58d457420d36ecef3b11d Mon Sep 17 00:00:00 2001 From: Oliver Boehlk Date: Wed, 13 May 2020 20:36:12 +0200 Subject: [PATCH 3/3] revert authentication skip --- backend/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 43edb04..d36ceae 100644 --- a/backend/index.js +++ b/backend/index.js @@ -164,7 +164,6 @@ app.put("/API/user/create", function (req, res) { }); app.all("*", function (req, res, next) { - return next(); if (req.isAuthenticated()) { return next(); }