From 2d7bf10fc2874d424aac4fc55a1588a8ec745088 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Wed, 21 Jun 2023 17:44:03 +0200 Subject: [PATCH] Repair account deletion --- .../src/services/families_service.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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(()) }