diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 1949bd0..278f35f 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -330,6 +330,9 @@ pub fn delete(user_id: &UserID) -> ResultBoxError { // Delete all the notifications related with the user notifications_helper::delete_all_related_with_user(user_id)?; + // Delete all user friends, including friendship requests + friends_helper::delete_all_user(user_id)?; + // TODO : continue work here Ok(()) diff --git a/src/helpers/friends_helper.rs b/src/helpers/friends_helper.rs index 79fb1d6..da17020 100644 --- a/src/helpers/friends_helper.rs +++ b/src/helpers/friends_helper.rs @@ -247,6 +247,17 @@ pub fn count_requests(user_id: &UserID) -> ResultBoxError { .map(|r| r as u64) } +/// Delete all the friends of a given user +pub fn delete_all_user(user_id: &UserID) -> ResultBoxError { + database::DeleteQuery::new(FRIENDS_TABLE) + .cond_user_id("ID_personne", user_id) + .exec()?; + + database::DeleteQuery::new(FRIENDS_TABLE) + .cond_user_id("ID_amis", user_id) + .exec() +} + /// Turn a database entry into a Friend structure fn db_to_friend(row: &database::RowResult) -> ResultBoxError { Ok(Friend {