use new day api
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user