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) {
|
app.get('/API/day', function (req, res) {
|
||||||
var date = new Date(req.query.date);
|
|
||||||
const kind = parseInt(req.query.kind);
|
const kind = parseInt(req.query.kind);
|
||||||
if (date instanceof Date && Number.isInteger(kind)) {
|
if (Number.isInteger(kind)) {
|
||||||
//Mock Data:
|
//Mock Data:
|
||||||
if (kind === -1) return res.send(mockDataDay);
|
if (kind === -1) return res.send(mockDataDay);
|
||||||
|
|
||||||
if (!isNaN(date.getTime()) && kind >= 1 && kind <= 113) {
|
if (kind >= 1 && kind <= 113) {
|
||||||
const daybegin = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
var dayend = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
||||||
date.setDate(date.getDate() + 1);
|
var daybegin = new Date();
|
||||||
const dayend = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
daybegin.setDate(daybegin.getDate() - 1);
|
||||||
const querystring = `SELECT time, price FROM market WHERE kind = ${kind} AND time > "${daybegin}" AND time < "${dayend}"`
|
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) {
|
connection.query(querystring, function (error, results, fields) {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
res.status(status.INTERNAL_SERVER_ERROR).send("database connection failed");
|
||||||
}
|
}
|
||||||
res.send(results);
|
res.send(results);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user