add-weekfunction-for-backend #58
@@ -186,7 +186,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 +203,38 @@ app.get('/API/day', function (req, res) {
|
||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user