Can join a family
This commit is contained in:
@ -4,7 +4,7 @@ use crate::models::{Family, FamilyID, Membership, NewFamily, NewMembership, User
|
||||
use crate::schema::{families, memberships};
|
||||
use crate::utils::string_utils::rand_str;
|
||||
use crate::utils::time_utils::time;
|
||||
use diesel::RunQueryDsl;
|
||||
use diesel::prelude::*;
|
||||
|
||||
/// Create a new family, with an initial administrator
|
||||
pub async fn create(name: &str, user_id: UserID) -> anyhow::Result<Family> {
|
||||
@ -45,12 +45,33 @@ pub async fn add_member(
|
||||
})
|
||||
}
|
||||
|
||||
/// Find a family by invitation code
|
||||
pub async fn get_by_invitation_code(code: &str) -> anyhow::Result<Family> {
|
||||
db_connection::execute(|conn| {
|
||||
families::table
|
||||
.filter(families::dsl::invitation_code.eq(code))
|
||||
.first(conn)
|
||||
})
|
||||
}
|
||||
|
||||
/// Check if a given user is member of a family or not
|
||||
pub async fn is_member(family_id: FamilyID, user_id: UserID) -> anyhow::Result<bool> {
|
||||
db_connection::execute(|conn| {
|
||||
memberships::table
|
||||
.filter(memberships::dsl::family_id.eq(family_id.0))
|
||||
.filter(memberships::dsl::user_id.eq(user_id.0))
|
||||
.count()
|
||||
.get_result(conn)
|
||||
})
|
||||
.map(|c: i64| c > 0)
|
||||
}
|
||||
|
||||
/// Remove a membership to a family
|
||||
pub async fn remove_membership(family_id: FamilyID, user_id: UserID) {
|
||||
pub async fn remove_membership(_family_id: FamilyID, _user_id: UserID) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// 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!()
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ pub enum RatedAction {
|
||||
StartOpenIDLogin,
|
||||
RequestReplacePasswordSignedIn,
|
||||
RequestDeleteAccount,
|
||||
JoinFamily,
|
||||
}
|
||||
|
||||
impl RatedAction {
|
||||
@ -24,6 +25,7 @@ impl RatedAction {
|
||||
RatedAction::StartOpenIDLogin => "start-oidc-login",
|
||||
RatedAction::RequestReplacePasswordSignedIn => "req-pwd-signed-in",
|
||||
RatedAction::RequestDeleteAccount => "req-del-acct",
|
||||
RatedAction::JoinFamily => "join-family",
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +38,7 @@ impl RatedAction {
|
||||
RatedAction::StartOpenIDLogin => 30,
|
||||
RatedAction::RequestReplacePasswordSignedIn => 5,
|
||||
RatedAction::RequestDeleteAccount => 5,
|
||||
RatedAction::JoinFamily => 10,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user