Add account type
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use crate::connections::db_connection::db;
|
||||
use crate::controllers::server_controller::ServerConstraints;
|
||||
use crate::models::accounts::{Account, AccountID, NewAccount};
|
||||
use crate::models::accounts::{Account, AccountID, AccountType, NewAccount};
|
||||
use crate::models::users::UserID;
|
||||
use crate::schema::accounts;
|
||||
use crate::utils::time_utils::time;
|
||||
@ -10,6 +10,7 @@ use diesel::prelude::*;
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct UpdateAccountQuery {
|
||||
pub name: String,
|
||||
pub r#type: AccountType,
|
||||
}
|
||||
|
||||
impl UpdateAccountQuery {
|
||||
@ -31,6 +32,7 @@ pub async fn create(user_id: UserID, query: &UpdateAccountQuery) -> anyhow::Resu
|
||||
user_id: user_id.0,
|
||||
time_create: time() as i64,
|
||||
time_update: time() as i64,
|
||||
type_: query.r#type.to_string(),
|
||||
};
|
||||
|
||||
let res: Account = diesel::insert_into(accounts::table)
|
||||
@ -48,6 +50,7 @@ pub async fn update(id: AccountID, q: &UpdateAccountQuery) -> anyhow::Result<()>
|
||||
.set((
|
||||
accounts::dsl::time_update.eq(time() as i64),
|
||||
accounts::dsl::name.eq(&q.name),
|
||||
accounts::dsl::type_.eq(&q.r#type.to_string()),
|
||||
))
|
||||
.execute(&mut db()?)?;
|
||||
|
||||
|
Reference in New Issue
Block a user