Automatically delete members when families are deleted
This commit is contained in:
@ -25,6 +25,15 @@ pub async fn get_by_id(id: MemberID) -> anyhow::Result<Member> {
|
||||
db_connection::execute(|conn| members::table.filter(members::dsl::id.eq(id.0)).first(conn))
|
||||
}
|
||||
|
||||
/// Get all the members of a family
|
||||
pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<Member>> {
|
||||
db_connection::execute(|conn| {
|
||||
members::table
|
||||
.filter(members::dsl::family_id.eq(id.0))
|
||||
.get_results(conn)
|
||||
})
|
||||
}
|
||||
|
||||
/// Check whether a member with a given id exists or not
|
||||
pub async fn exists(family_id: FamilyID, member_id: MemberID) -> anyhow::Result<bool> {
|
||||
db_connection::execute(|conn| {
|
||||
@ -89,3 +98,11 @@ pub async fn delete(member: &Member) -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Delete all the members of a family
|
||||
pub async fn delete_all_family(family_id: FamilyID) -> anyhow::Result<()> {
|
||||
for m in get_all_of_family(family_id).await? {
|
||||
delete(&m).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user