Repair account deletion

This commit is contained in:
Pierre HUBERT 2023-06-21 17:44:03 +02:00
parent a94b26b23c
commit 2d7bf10fc2

View File

@ -70,7 +70,7 @@ pub async fn is_member(family_id: FamilyID, user_id: UserID) -> anyhow::Result<b
.map(|c: i64| c > 0) .map(|c: i64| c > 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<Vec<FamilyMembership>> { pub async fn get_user_family_memberships(user_id: UserID) -> anyhow::Result<Vec<FamilyMembership>> {
db_connection::execute(|conn| { db_connection::execute(|conn| {
families_memberships::table families_memberships::table
@ -79,6 +79,15 @@ pub async fn get_user_family_memberships(user_id: UserID) -> anyhow::Result<Vec<
}) })
} }
/// Get the memberships of a user, without family info
pub async fn get_user_memberships(user_id: UserID) -> anyhow::Result<Vec<Membership>> {
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 /// Get information about a membership of a user
pub async fn get_membership(family_id: FamilyID, user_id: UserID) -> anyhow::Result<Membership> { pub async fn get_membership(family_id: FamilyID, user_id: UserID) -> anyhow::Result<Membership> {
db_connection::execute(|conn| { 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 /// Remove all memberships of user
pub async fn remove_all_user_membership(_user_id: UserID) -> anyhow::Result<()> { pub async fn remove_all_user_membership(user_id: UserID) -> anyhow::Result<()> {
todo!() for m in get_user_memberships(user_id).await? {
remove_membership(m.family_id(), user_id).await?;
}
Ok(())
} }