Date updates
rodzic
35ca8a3364
commit
4d87ac63a6
|
@ -11,6 +11,10 @@ router.get("/", async (req, res, next) => {
|
||||||
let year = date.getFullYear();
|
let year = date.getFullYear();
|
||||||
let month = date.getMonth() + 1;
|
let month = date.getMonth() + 1;
|
||||||
let day = date.getDate();
|
let day = date.getDate();
|
||||||
|
|
||||||
|
// ignore time offsets
|
||||||
|
let formattedDate = formatDate(year,month,day);
|
||||||
|
|
||||||
let conn;
|
let conn;
|
||||||
try {
|
try {
|
||||||
conn = await pool.getConnection();
|
conn = await pool.getConnection();
|
||||||
|
@ -60,7 +64,7 @@ router.get("/", async (req, res, next) => {
|
||||||
t.origin = ? and \
|
t.origin = ? and \
|
||||||
t.dest = ?";
|
t.dest = ?";
|
||||||
|
|
||||||
var results = await conn.query(query, [month,day,origin,dest,year,month,day,month,day,origin,dest,date,origin,dest]);
|
var results = await conn.query(query, [month,day,origin,dest,year,month,day,month,day,origin,dest,formattedDate,origin,dest]);
|
||||||
|
|
||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
var analyzedResults = analyzeResults(results);
|
var analyzedResults = analyzeResults(results);
|
||||||
|
@ -77,6 +81,15 @@ router.get("/", async (req, res, next) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function formatDate(year,month,day) {
|
||||||
|
if (month.length < 2)
|
||||||
|
month = '0' + month;
|
||||||
|
if (day.length < 2)
|
||||||
|
day = '0' + day;
|
||||||
|
|
||||||
|
return [year, month, day].join('-');
|
||||||
|
}
|
||||||
|
|
||||||
// secret (scoring) sauce
|
// secret (scoring) sauce
|
||||||
function analyzeResults(items) {
|
function analyzeResults(items) {
|
||||||
let prices = items.map(item => item.price)
|
let prices = items.map(item => item.price)
|
||||||
|
|
Ładowanie…
Reference in New Issue