diff --git a/backend/index.js b/backend/index.js index 17e4ad0..2356538 100644 --- a/backend/index.js +++ b/backend/index.js @@ -32,6 +32,7 @@ var sessionStore = new MySQLStore({ const mockDataDay = require('./mockdata-test/day.json'); const mockDataWeek = require('./mockdata-test/week.json'); +//const mockDataMonth = require('./mockdata-test/month.json'); var resourceList; const saltRounds = 13; @@ -241,6 +242,35 @@ app.get('/API/week', function (req, res) { return res.status(status.BAD_REQUEST).send("invalid data provided"); }); +app.get('/API/month', function (req, res) { + const kind = parseInt(req.query.kind); + if (Number.isInteger(kind)) { + //Mock Data: + //if (kind === -1 || DEBUG) return res.send(mockDataMonth); + + if (kind >= 1 && kind <= 113) { + var day = new Date(); + var querying = ""; + for (let i = 0; i < 30; i++) { + let currentday = day.toMysqlFormat().split(" ")[0]; + querying += `SELECT "${currentday}" as id,kind,quality,AVG(price) FROM marketv2 WHERE kind = 1 AND TIME >= "${currentday} 00:00:00" AND TIME <= "${currentday} 23:59:59" GROUP BY kind,quality ${i === 29 ? "" : "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); }); diff --git a/backend/mockdata-test/month.json b/backend/mockdata-test/month.json new file mode 100644 index 0000000..e69de29