From 4967d52a88fc68b63e46bec6d65be96cd34891f1 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Wed, 30 Mar 2022 05:49:43 +0530 Subject: [PATCH] Bug fix: rate history API not working --- src/price.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/price.js b/src/price.js index 1c47b8e..637c6b0 100644 --- a/src/price.js +++ b/src/price.js @@ -41,9 +41,9 @@ function getHistory(asset, duration) { return new Promise((resolve, reject) => { duration = getHistory.validateDuration(duration); let statement = "SELECT " + - (!duration || duration.endsWith("year") ? "DATE(rec_time) AS time, AVG(rate) as rate" : "rec_time AS time, rate") + - " WHERE asset=?" + (duration ? " AND rec_time >= NOW() - INTERVAL " + duration : "") + - (!duration || duration.endsWith("year") ? " GROUP BY time" : "") + + (!duration || duration.endsWith("month") || duration.endsWith("year") ? "DATE(rec_time) AS time, AVG(rate) as rate" : "rec_time AS time, rate") + + " FROM PriceHistory WHERE asset=?" + (duration ? " AND rec_time >= NOW() - INTERVAL " + duration : "") + + (!duration || duration.endsWith("month") || duration.endsWith("year") ? " GROUP BY time" : "") + " ORDER BY time"; DB.query(statement, asset) .then(result => resolve(result))