From ca30554eb929da0794ccaba051550dc314196909 Mon Sep 17 00:00:00 2001 From: Oliver Boehlk Date: Sun, 19 Apr 2020 17:30:30 +0200 Subject: [PATCH] use new day api --- backend/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/index.js b/backend/index.js index 8b1707d..4b89d90 100644 --- a/backend/index.js +++ b/backend/index.js @@ -42,20 +42,20 @@ app.all("/*", function (req, res, next) { }) app.get('/API/day', function (req, res) { - var date = new Date(req.query.date); const kind = parseInt(req.query.kind); - if (date instanceof Date && Number.isInteger(kind)) { + if (Number.isInteger(kind)) { //Mock Data: if (kind === -1) return res.send(mockDataDay); - if (!isNaN(date.getTime()) && kind >= 1 && kind <= 113) { - const daybegin = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; - date.setDate(date.getDate() + 1); - const dayend = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; - const querystring = `SELECT time, price FROM market WHERE kind = ${kind} AND time > "${daybegin}" AND time < "${dayend}"` + if (kind >= 1 && kind <= 113) { + var dayend = new Date().toISOString().slice(0, 19).replace('T', ' '); + var daybegin = new Date(); + daybegin.setDate(daybegin.getDate() - 1); + daybegin = daybegin.toISOString().slice(0, 19).replace('T', ' '); + const querystring = `SELECT time, price, quality FROM marketv2 WHERE kind = ${kind} AND time > "${daybegin}" AND time < "${dayend}" ORDER BY quality, time`; connection.query(querystring, function (error, results, fields) { if (error) { - throw error; + res.status(status.INTERNAL_SERVER_ERROR).send("database connection failed"); } res.send(results); });