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.
This commit is contained in:
Brandon Presley 2022-10-01 13:31:05 +13:00
parent 9d42760dff
commit a02247542e
1 changed files with 4 additions and 2 deletions

View File

@ -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();
};