Compare commits
1 Commits
master
...
feature/st
Author | SHA1 | Date | |
---|---|---|---|
ebe9a392ca |
|
@ -45,18 +45,30 @@ export default function StartPlan() {
|
||||||
const questions = workouts
|
const questions = workouts
|
||||||
.map((workout, index) => `('${workout}',${index})`)
|
.map((workout, index) => `('${workout}',${index})`)
|
||||||
.join(",");
|
.join(",");
|
||||||
const select = `
|
const newCounts = await AppDataSource.manager
|
||||||
SELECT workouts.name, COUNT(sets.id) as total, sets.sets
|
.createQueryBuilder()
|
||||||
FROM (select 0 as name, 0 as sequence union values ${questions}) as workouts
|
.select("workouts.name")
|
||||||
LEFT JOIN sets ON sets.name = workouts.name
|
.addSelect("COUNT(sets.id)", "total")
|
||||||
AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime')
|
.addSelect("sets.sets")
|
||||||
AND NOT sets.hidden
|
.from((qb) => {
|
||||||
GROUP BY workouts.name
|
const subQuery = qb
|
||||||
ORDER BY workouts.sequence
|
.subQuery()
|
||||||
LIMIT -1
|
.select("0", "name")
|
||||||
OFFSET 1
|
.addSelect("0", "sequence")
|
||||||
`;
|
.from("workouts", "workouts")
|
||||||
const newCounts = await AppDataSource.manager.query(select);
|
.getQuery();
|
||||||
|
return `(${subQuery} UNION ALL values ${questions})`;
|
||||||
|
}, "workouts")
|
||||||
|
.leftJoin(
|
||||||
|
"sets",
|
||||||
|
"sets",
|
||||||
|
"sets.name = workouts.name AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime') AND NOT sets.hidden"
|
||||||
|
)
|
||||||
|
.groupBy("workouts.name")
|
||||||
|
.orderBy("workouts.sequence")
|
||||||
|
.limit(-1)
|
||||||
|
.offset(1)
|
||||||
|
.getRawMany();
|
||||||
console.log(`${StartPlan.name}.focus:`, { newCounts });
|
console.log(`${StartPlan.name}.focus:`, { newCounts });
|
||||||
setCounts(newCounts);
|
setCounts(newCounts);
|
||||||
}, [workouts]);
|
}, [workouts]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user