diff --git a/geneit_backend/src/services/families_service.rs b/geneit_backend/src/services/families_service.rs index 171d905..fe41744 100644 --- a/geneit_backend/src/services/families_service.rs +++ b/geneit_backend/src/services/families_service.rs @@ -70,7 +70,7 @@ pub async fn is_member(family_id: FamilyID, user_id: UserID) -> anyhow::Result 0) } -/// Get the memberships of a user +/// Get the memberships of a user, with family info pub async fn get_user_family_memberships(user_id: UserID) -> anyhow::Result> { db_connection::execute(|conn| { families_memberships::table @@ -79,6 +79,15 @@ pub async fn get_user_family_memberships(user_id: UserID) -> anyhow::Result anyhow::Result> { + db_connection::execute(|conn| { + memberships::table + .filter(memberships::dsl::user_id.eq(user_id.0)) + .get_results(conn) + }) +} + /// Get information about a membership of a user pub async fn get_membership(family_id: FamilyID, user_id: UserID) -> anyhow::Result { db_connection::execute(|conn| { @@ -178,6 +187,10 @@ pub async fn remove_membership(family_id: FamilyID, user_id: UserID) -> anyhow:: } /// Remove all memberships of user -pub async fn remove_all_user_membership(_user_id: UserID) -> anyhow::Result<()> { - todo!() +pub async fn remove_all_user_membership(user_id: UserID) -> anyhow::Result<()> { + for m in get_user_memberships(user_id).await? { + remove_membership(m.family_id(), user_id).await?; + } + + Ok(()) }