feat: update query

This commit is contained in:
Maulana Sodiqin
2025-03-21 13:25:22 +07:00
parent 413a28c089
commit a0f263bb4f
3 changed files with 46 additions and 42 deletions
+4 -29
View File
@@ -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()),