From 3be6c0b1a46072df53badf3960d36ad0661735b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Wed, 20 Nov 2024 00:22:58 +0800 Subject: [PATCH] refactor(account): remove role field from register form --- src/models/account.rs | 4 ++-- src/routes/account.rs | 3 +-- src/utils/account.rs | 6 +----- tests/account.rs | 1 - 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/models/account.rs b/src/models/account.rs index f5c26d5..ca3a8d0 100644 --- a/src/models/account.rs +++ b/src/models/account.rs @@ -4,10 +4,10 @@ use surrealdb::sql::Thing; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub enum Role { - SuperAdmin, - Admin, #[default] User, + SuperAdmin, + Admin, Reserve, } diff --git a/src/routes/account.rs b/src/routes/account.rs index 3a6a4d1..943e3db 100644 --- a/src/routes/account.rs +++ b/src/routes/account.rs @@ -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)] diff --git a/src/utils/account.rs b/src/utils/account.rs index 9cbd93d..f3365e0 100644 --- a/src/utils/account.rs +++ b/src/utils/account.rs @@ -24,11 +24,7 @@ pub async fn create(db: &Surreal, register: RegisterData) -> Result 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() }) diff --git a/tests/account.rs b/tests/account.rs index e7c9d00..e06af1b 100644 --- a/tests/account.rs +++ b/tests/account.rs @@ -69,7 +69,6 @@ async fn test_register() -> Result<()> { username: "fu050409".to_string(), password: "password".to_string(), email: "email@example.com".to_string(), - role: 1, }) .dispatch() .await;