feat: update logic

This commit is contained in:
Maulana Sodiqin
2025-03-30 02:46:16 +07:00
parent a97044edfc
commit 0816566d03
23 changed files with 782 additions and 305 deletions
+66 -36
View File
@@ -5,12 +5,17 @@ use surrealdb::sql::Thing;
use utoipa::ToSchema;
use validator::Validate;
use crate::RolesItemDto;
use crate::{RolesItemDto, RolesItemDtoRaw};
lazy_static! {
static ref PASSWORD_REGEX: Regex = Regex::new(r"^[A-Za-z\d@$!%*?&]{8,}$").unwrap();
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersActiveInactiveRequestDto {
pub is_active: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
pub struct UsersCreateRequestDto {
#[validate(
@@ -73,11 +78,15 @@ pub struct UsersUpdateRequestDto {
pub referral_code: Option<String>,
pub referred_by: Option<String>,
pub is_active: bool,
#[validate(length(min = 16, message = "NIK at must have 16 character"))]
#[validate(length(min = 16, message = "NIK at least have 16 character"))]
pub identity_number: Option<String>,
#[validate(length(min = 1, message = "Religion is required"))]
pub religion: Option<String>,
#[validate(length(min = 1, message = "Gender is required"))]
pub gender: Option<String>,
#[validate(length(min = 1, message = "Birthdate is required"))]
pub birthdate: Option<String>,
#[validate(length(min = 1, message = "Avatar is required"))]
pub avatar: Option<String>,
pub role_id: String,
}
@@ -95,16 +104,20 @@ pub struct UsersItemDto {
pub student_type: String,
pub is_active: bool,
pub is_profile_completed: bool,
pub is_deleted: bool,
pub identity_number: Option<String>,
pub religion: Option<String>,
pub gender: Option<String>,
pub birthdate: Option<String>,
pub password: String,
pub created_at: String,
pub updated_at: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UsersItemDtoRaw {
pub id: Thing,
pub role: Thing,
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersDetailItemDto {
pub id: String,
pub role: RolesItemDto,
pub fullname: String,
pub email: String,
pub avatar: Option<String>,
@@ -120,36 +133,53 @@ pub struct UsersItemDtoRaw {
pub birthdate: Option<String>,
}
impl From<UsersItemDtoRaw> for UsersItemDto {
fn from(raw: UsersItemDtoRaw) -> Self {
Self {
id: raw.id.id.to_string(),
role: RolesItemDto {
id: raw.role.id.to_string(),
name: "".into(),
is_deleted: false,
permissions: vec![],
created_at: None,
updated_at: None,
},
fullname: raw.fullname,
email: raw.email,
avatar: raw.avatar,
phone_number: raw.phone_number,
referred_by: raw.referred_by,
referral_code: raw.referral_code,
student_type: raw.student_type,
is_active: raw.is_active,
is_profile_completed: raw.is_profile_completed,
identity_number: raw.identity_number,
religion: raw.religion,
gender: raw.gender,
birthdate: raw.birthdate,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersActiveInactiveRequestDto {
pub struct UsersListItemDto {
pub id: String,
pub role: String,
pub fullname: String,
pub email: String,
pub avatar: Option<String>,
pub phone_number: String,
pub referred_by: Option<String>,
pub referral_code: Option<String>,
pub student_type: String,
pub is_active: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UsersListItemDtoRaw {
pub id: Thing,
pub role: Option<String>,
pub fullname: String,
pub email: String,
pub avatar: Option<String>,
pub phone_number: String,
pub referred_by: Option<String>,
pub referral_code: Option<String>,
pub student_type: String,
pub is_active: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UsersItemDtoRaw {
pub id: Thing,
pub fullname: String,
pub email: String,
pub avatar: Option<String>,
pub phone_number: String,
pub referred_by: Option<String>,
pub referral_code: Option<String>,
pub student_type: String,
pub is_active: bool,
pub is_profile_completed: bool,
pub is_deleted: bool,
pub identity_number: Option<String>,
pub religion: Option<String>,
pub gender: Option<String>,
pub birthdate: Option<String>,
pub role: RolesItemDtoRaw,
pub password: String,
pub created_at: String,
pub updated_at: String,
}