Skip to content

Commit

Permalink
refactor(account): remove role field from register form
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Nov 19, 2024
1 parent 94b39ce commit 3be6c0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/models/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use surrealdb::sql::Thing;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub enum Role {
SuperAdmin,
Admin,
#[default]
User,
SuperAdmin,
Admin,
Reserve,
}

Expand Down
3 changes: 1 addition & 2 deletions src/routes/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use crate::{
#[derive(Serialize, Deserialize)]
pub struct RegisterData {
pub username: String,
pub password: String,
pub email: String,
pub role: u8,
pub password: String,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
6 changes: 1 addition & 5 deletions src/utils/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ pub async fn create(db: &Surreal<Client>, register: RegisterData) -> Result<Opti
username: register.username,
password: register.password,
email: register.email,
role: match register.role {
0 => Role::User,
1 => Role::Reserve,
_ => return Err(anyhow::anyhow!("Invalid role type: {}", register.role)),
},
role: Role::User,
created_at: chrono::Local::now().naive_local(),
..Default::default()
})
Expand Down
1 change: 0 additions & 1 deletion tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ async fn test_register() -> Result<()> {
username: "fu050409".to_string(),
password: "password".to_string(),
email: "[email protected]".to_string(),
role: 1,
})
.dispatch()
.await;
Expand Down

0 comments on commit 3be6c0b

Please sign in to comment.