From a02247542e47d9c2f90a7aaf1530c03872e85aff Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sat, 1 Oct 2022 13:31:05 +1300 Subject: [PATCH] Group created by month when period is yearly Possible solution to #78 We should keep this issue up for a while longer to see how this solution feels. --- best.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/best.service.ts b/best.service.ts index df00274..43eee49 100644 --- a/best.service.ts +++ b/best.service.ts @@ -36,12 +36,14 @@ export const getWeightsBy = async ( FROM sets WHERE name = ? AND NOT hidden AND DATE(created) >= DATE('now', 'weekday 0', ?) - GROUP BY name, STRFTIME('%Y-%m-%d', created) + GROUP BY name, STRFTIME(?, created) `; let difference = '-7 days'; if (period === Periods.Monthly) difference = '-1 months'; else if (period === Periods.Yearly) difference = '-1 years'; - const [result] = await db.executeSql(select, [name, difference]); + let group = '%Y-%m-%d'; + if (period === Periods.Yearly) group = '%Y-%m'; + const [result] = await db.executeSql(select, [name, difference, group]); return result.rows.raw(); };