feat: update query
This commit is contained in:
@@ -11,7 +11,10 @@ use crate::{
|
||||
UsersSchema,
|
||||
};
|
||||
use axum::{http::StatusCode, response::Response};
|
||||
use surrealdb::sql::{Id, Thing};
|
||||
use surrealdb::{
|
||||
sql::{Id, Thing},
|
||||
Uuid,
|
||||
};
|
||||
|
||||
pub struct AuthService;
|
||||
|
||||
@@ -140,25 +143,20 @@ impl AuthService {
|
||||
|
||||
match user_repo
|
||||
.query_create_user(UsersSchema {
|
||||
id: Some("".to_string()),
|
||||
id: Uuid::new_v4().to_string(),
|
||||
email: new_user.email.clone(),
|
||||
fullname: new_user.fullname.clone(),
|
||||
password: new_user.password.clone(),
|
||||
is_active: false,
|
||||
role_id: "".to_string(),
|
||||
avatar: Some("".to_string()),
|
||||
phone_number: new_user.phone_number.clone(),
|
||||
referral_code: new_user.referral_code.clone(),
|
||||
referred_by: new_user.referred_by.clone(),
|
||||
identity_number: Some("".to_string()),
|
||||
student_type: new_user.student_type.clone(),
|
||||
religion: Some("".to_string()),
|
||||
gender: Some("".to_string()),
|
||||
birthdate: Some("".to_string()),
|
||||
is_profile_completed: Some(false),
|
||||
created_at: Some(get_iso_date()),
|
||||
updated_at: Some(get_iso_date()),
|
||||
role: role_thing,
|
||||
is_active: false,
|
||||
is_profile_completed: false,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::{UsersActiveInactiveSchema, UsersSchema, UsersSetNewPasswordSchema};
|
||||
use crate::{get_iso_date, AppState, ResourceEnum};
|
||||
use crate::{AppState, ResourceEnum};
|
||||
use anyhow::{bail, Result};
|
||||
use surrealdb::Uuid;
|
||||
|
||||
pub struct UsersRepository<'a> {
|
||||
state: &'a AppState,
|
||||
@@ -19,39 +18,15 @@ impl<'a> UsersRepository<'a> {
|
||||
.await?;
|
||||
match result {
|
||||
Some(response) => Ok(response),
|
||||
None => {
|
||||
bail!("User not found")
|
||||
}
|
||||
None => bail!("User not found"),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query_create_user(&self, data: UsersSchema) -> Result<String> {
|
||||
let id = Uuid::new_v4().to_string();
|
||||
let db = &self.state.surrealdb;
|
||||
|
||||
let record: Option<UsersSchema> = db
|
||||
.create((ResourceEnum::Users.to_string(), &id))
|
||||
.content(UsersSchema {
|
||||
id: Some(id.clone()),
|
||||
role_id: data.role_id.clone(),
|
||||
fullname: data.fullname.clone(),
|
||||
email: data.email.clone(),
|
||||
password: data.password.clone(),
|
||||
avatar: data.avatar.clone(),
|
||||
phone_number: data.phone_number.clone(),
|
||||
referral_code: data.referral_code.clone(),
|
||||
referred_by: data.referred_by.clone(),
|
||||
identity_number: data.identity_number.clone(),
|
||||
student_type: data.student_type.clone(),
|
||||
religion: data.religion.clone(),
|
||||
gender: data.gender.clone(),
|
||||
birthdate: data.birthdate.clone(),
|
||||
is_active: data.is_active.clone(),
|
||||
is_profile_completed: data.is_profile_completed.clone(),
|
||||
role: data.role.clone(),
|
||||
created_at: Some(get_iso_date()),
|
||||
updated_at: Some(get_iso_date()),
|
||||
})
|
||||
.create((ResourceEnum::Users.to_string(), &data.id))
|
||||
.content(data)
|
||||
.await?;
|
||||
match record {
|
||||
Some(_) => Ok("Success create user".into()),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::sql::Thing;
|
||||
use surrealdb::sql::{Id, Thing};
|
||||
|
||||
use crate::ResourceEnum;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct UsersSchema {
|
||||
pub id: Option<String>,
|
||||
pub id: String,
|
||||
pub role_id: String,
|
||||
pub fullname: String,
|
||||
pub email: String,
|
||||
@@ -18,12 +20,41 @@ pub struct UsersSchema {
|
||||
pub religion: Option<String>,
|
||||
pub gender: Option<String>,
|
||||
pub birthdate: Option<String>,
|
||||
pub is_profile_completed: Option<bool>,
|
||||
pub is_profile_completed: bool,
|
||||
pub role: Thing,
|
||||
pub created_at: Option<String>,
|
||||
pub updated_at: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for UsersSchema {
|
||||
fn default() -> Self {
|
||||
UsersSchema {
|
||||
id: String::new(),
|
||||
role_id: String::new(),
|
||||
fullname: String::new(),
|
||||
email: String::new(),
|
||||
password: String::new(),
|
||||
avatar: None,
|
||||
phone_number: String::new(),
|
||||
referral_code: None,
|
||||
referred_by: None,
|
||||
identity_number: None,
|
||||
is_active: false,
|
||||
student_type: String::new(),
|
||||
religion: None,
|
||||
gender: None,
|
||||
birthdate: None,
|
||||
role: Thing::from((
|
||||
ResourceEnum::Roles.to_string(),
|
||||
Id::String("".to_string()),
|
||||
)),
|
||||
is_profile_completed: false,
|
||||
created_at: None,
|
||||
updated_at: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct UsersSetNewPasswordSchema {
|
||||
pub email: String,
|
||||
|
||||
Reference in New Issue
Block a user