Skip to content

Commit

Permalink
fix(fitness): account for non-existent workouts in PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Aug 25, 2024
1 parent bfd4b53 commit 7ccfcad
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions crates/services/fitness/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,15 @@ pub async fn calculate_and_commit(
.and_then(|record| record.sets.first());
let set = sets.get_mut(set_idx).unwrap();
if let Some(r) = possible_record {
let workout = Workout::find_by_id(r.workout_id.clone())
.one(db)
.await?
.unwrap();
let workout_set =
workout.information.exercises[r.exercise_idx].sets[r.set_idx].clone();
if set.get_personal_best(best_type) > workout_set.get_personal_best(best_type) {
if let Some(ref mut set_personal_bests) = set.personal_bests {
set_personal_bests.push(*best_type);
if let Some(workout) = Workout::find_by_id(r.workout_id.clone()).one(db).await? {
let workout_set =
workout.information.exercises[r.exercise_idx].sets[r.set_idx].clone();
if set.get_personal_best(best_type) > workout_set.get_personal_best(best_type) {
if let Some(ref mut set_personal_bests) = set.personal_bests {
set_personal_bests.push(*best_type);
}
total.personal_bests_achieved += 1;
}
total.personal_bests_achieved += 1;
}
} else {
if let Some(ref mut set_personal_bests) = set.personal_bests {
Expand Down

0 comments on commit 7ccfcad

Please sign in to comment.