Skip to content

Commit

Permalink
Fixed date sorting problem for history page
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kolomanski committed May 7, 2023
1 parent 2c20e15 commit e640e29
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions js/dbmgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const path = require('path');
const getTodayDate = function () {
let date = new Date();
let yyyy = date.getFullYear();
let mm = date.getMonth() + 1;
let dd = date.getDate();
let mm = String(date.getMonth() + 1).padStart(2,'0');
let dd = String(date.getDate()).padStart(2,'0');

let full_date = yyyy.toString() + "-" + mm.toString() + "-" + dd.toString()

Expand Down Expand Up @@ -204,10 +204,10 @@ getHistory = function(last_days = 6, separate = true) {
days_to_fetch.push(available_days[day]["date"]);
}


query = separate ?
`SELECT * FROM daily WHERE Date in ('${days_to_fetch.join("','")}');` :
`SELECT daily.*, SUM(daily.amount) AS amount, SUM(daily.kcal) AS kcal FROM daily WHERE daily.date in ('${days_to_fetch.join("','")}') GROUP BY daily.name, daily.date ORDER BY daily.date;`;
`SELECT daily.*, SUM(daily.amount) AS amount, SUM(daily.kcal) AS kcal
FROM daily WHERE daily.date in ('${days_to_fetch.join("','")}') GROUP BY daily.date, daily.name ORDER BY daily.date ASC;`;
let history_data = db.prepare(query).all();
return history_data;
}
Expand Down

0 comments on commit e640e29

Please sign in to comment.