Skip to content

Commit

Permalink
fix(services/fitness): do not discard user exercise settings during w…
Browse files Browse the repository at this point in the history
…orkout revision
  • Loading branch information
IgnisDa committed Dec 25, 2024
1 parent ace4d17 commit a405fe3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/services/fitness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependent-models = { path = "../../models/dependent" }
dependent-utils = { path = "../../utils/dependent" }
enum-models = { path = "../../models/enum" }
fitness-models = { path = "../../models/fitness" }
futures = { workspace = true }
migrations = { path = "../../migrations" }
nanoid = { workspace = true }
reqwest = { workspace = true }
Expand Down
14 changes: 12 additions & 2 deletions crates/services/fitness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use fitness_models::{
UpdateUserWorkoutAttributesInput, UserMeasurementsListInput, UserToExerciseExtraInformation,
UserWorkoutInput, WorkoutInformation, WorkoutSetRecord, WorkoutSummary, WorkoutSummaryExercise,
};
use futures::TryStreamExt;
use migrations::AliasedExercise;
use nanoid::nanoid;
use sea_orm::{
Expand Down Expand Up @@ -602,11 +603,20 @@ impl FitnessService {
}

pub async fn revise_user_workouts(&self, user_id: String) -> Result<()> {
UserToEntity::delete_many()
let mut all_stream = UserToEntity::find()
.filter(user_to_entity::Column::UserId.eq(&user_id))
.filter(user_to_entity::Column::ExerciseId.is_not_null())
.exec(&self.0.db)
.stream(&self.0.db)
.await?;
while let Some(ute) = all_stream.try_next().await? {
let mut new = UserToExerciseExtraInformation::default();
let eei = ute.exercise_extra_information.clone().unwrap_or_default();
new.settings = eei.settings;
let mut ute: user_to_entity::ActiveModel = ute.into();
ute.exercise_num_times_interacted = ActiveValue::Set(None);
ute.exercise_extra_information = ActiveValue::Set(Some(new));
ute.update(&self.0.db).await?;
}
let workouts = Workout::find()
.filter(workout::Column::UserId.eq(&user_id))
.order_by_asc(workout::Column::EndTime)
Expand Down

0 comments on commit a405fe3

Please sign in to comment.