Massive/best.service.ts
Brandon Presley 7b401388b5 Get last now excludes todays sets - 1.129
Otherwise the minute you enter something it
becomes the last set. Much more useful to be
showing yesterdays working set instead.
2023-03-06 18:32:32 +13:00

30 lines
806 B
TypeScript

import {setRepo} from './db'
import GymSet from './gym-set'
export const getBestSet = async (name: string): Promise<GymSet> => {
return setRepo
.createQueryBuilder()
.select()
.addSelect('MAX(weight)', 'weight')
.where('name = :name', {name})
.groupBy('name')
.addGroupBy('reps')
.orderBy('weight', 'DESC')
.addOrderBy('reps', 'DESC')
.getOne()
}
export const getLast = async (name: string): Promise<GymSet> => {
return setRepo
.createQueryBuilder()
.where('name = :name', {name})
.andWhere('reps >= 5')
.andWhere("strftime('%Y-%m-%d', 'now', 'localtime') > created")
.groupBy("STRFTIME('%Y-%m-%d', created)")
.orderBy('created', 'DESC')
.select('reps')
.addSelect('MAX(weight) as weight')
.addSelect('unit')
.getRawOne()
}