feat: setup data
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use super::{UsersActiveInactiveSchema, UsersSetNewPasswordSchema};
|
||||
use crate::{v1::users_schema::UsersSchema, AppState, ResourceEnum};
|
||||
use super::{UsersActiveInactiveSchema, UsersSchema, UsersSetNewPasswordSchema};
|
||||
use crate::{get_iso_date, AppState, ResourceEnum};
|
||||
use anyhow::{bail, Result};
|
||||
use surrealdb::Uuid;
|
||||
|
||||
pub struct UsersRepository<'a> {
|
||||
state: &'a AppState,
|
||||
@@ -25,14 +26,31 @@ impl<'a> UsersRepository<'a> {
|
||||
}
|
||||
|
||||
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(), &data.email))
|
||||
.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(),
|
||||
is_active: false,
|
||||
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()),
|
||||
})
|
||||
.await?;
|
||||
match record {
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::sql::Thing;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct UsersSchema {
|
||||
pub email: String,
|
||||
pub id: Option<String>,
|
||||
pub role_id: String,
|
||||
pub fullname: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
pub avatar: Option<String>,
|
||||
pub phone_number: String,
|
||||
pub referral_code: Option<String>,
|
||||
pub referred_by: Option<String>,
|
||||
pub identity_number: Option<String>,
|
||||
pub is_active: bool,
|
||||
pub student_type: String,
|
||||
pub religion: Option<String>,
|
||||
pub gender: Option<String>,
|
||||
pub birthdate: Option<String>,
|
||||
pub is_profile_completed: Option<bool>,
|
||||
pub role: Thing,
|
||||
pub created_at: Option<String>,
|
||||
pub updated_at: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct UsersSetNewPasswordSchema {
|
||||
pub email: String,
|
||||
pub password: bool,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user