implement basic day query
This commit is contained in:
34
backend/index.js
Normal file
34
backend/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const express = require('express')
|
||||
const app = express();
|
||||
const status = require('http-status');
|
||||
var mysql = require('mysql');
|
||||
var connection = mysql.createConnection({
|
||||
host: 'localhost',
|
||||
user: 'simcompanies',
|
||||
password: '',
|
||||
database: 'simcompanies'
|
||||
});
|
||||
|
||||
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 (!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}"`
|
||||
connection.query(querystring, function (error, results, fields) {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
res.send(results);
|
||||
});
|
||||
}
|
||||
else
|
||||
res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
else
|
||||
res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
Reference in New Issue
Block a user