mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-17 13:31:12 +00:00
feat: delete parents based on form
This commit is contained in:
parent
6bd510fb38
commit
b6ac8f431f
4 changed files with 17 additions and 35 deletions
|
|
@ -15,6 +15,12 @@ impl Mutation {
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_parent(db: &DbConn, parent: Model) -> Result<DeleteResult, DbErr> {
|
||||
parent
|
||||
.delete(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn add_parent_details(
|
||||
db: &DbConn,
|
||||
parent: Model,
|
||||
|
|
|
|||
|
|
@ -237,7 +237,6 @@ impl From<&parent::Model> for EncryptedParentDetails {
|
|||
telephone: EncryptedString::try_from(&parent.telephone).ok(),
|
||||
email: EncryptedString::try_from(&parent.email).ok(),
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,35 +10,8 @@ use crate::{
|
|||
Mutation, Query, models::{candidate::{BaseCandidateResponse, CreateCandidateResponse}, auth::AuthenticableTrait}, utils::db::get_recipients,
|
||||
};
|
||||
|
||||
use super::{session_service::SessionService, application_service::ApplicationService, portfolio_service::PortfolioService};
|
||||
use super::{session_service::SessionService, portfolio_service::PortfolioService};
|
||||
|
||||
// TODO validation
|
||||
|
||||
/* pub struct FieldOfStudy {
|
||||
pub short_name: String,
|
||||
pub full_name: String,
|
||||
pub code: i32,
|
||||
}
|
||||
|
||||
impl FieldOfStudy {
|
||||
pub fn new(short_name: String, full_name: String, code: i32) -> Self {
|
||||
Self {
|
||||
short_name,
|
||||
full_name,
|
||||
code,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn code_str(&self) -> String {
|
||||
format!("{:04}", self.code)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum FieldsOfStudy {
|
||||
KB(FieldOfStudy),
|
||||
IT(FieldOfStudy),
|
||||
G(FieldOfStudy),
|
||||
} */
|
||||
|
||||
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
||||
|
||||
|
|
@ -136,17 +109,15 @@ impl CandidateService {
|
|||
.decrypt(admin_private_key).await?;
|
||||
let enc_details = EncryptedApplicationDetails::new(&dec_details, recipients).await?;
|
||||
|
||||
let candidate = Mutation::add_candidate_details(db, candidate, enc_details.candidate).await?;
|
||||
Mutation::add_candidate_details(db, candidate, enc_details.candidate).await?;
|
||||
for i in 0..enc_details.parents.len() {
|
||||
Mutation::add_parent_details(db, parents[i].clone(), enc_details.parents[i].clone()).await?;
|
||||
}
|
||||
|
||||
let details = ApplicationService::decrypt_all_details(priv_key_plain_text, db, candidate).await?;
|
||||
|
||||
Ok(
|
||||
CreateCandidateResponse {
|
||||
application_id: id,
|
||||
personal_id_number: personal_id_number,
|
||||
personal_id_number,
|
||||
password: new_password_plain,
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,10 +22,11 @@ impl ParentService {
|
|||
parents_details: &Vec<ParentDetails>,
|
||||
recipients: &Vec<String>,
|
||||
) -> Result<Vec<parent::Model>, ServiceError> {
|
||||
let found_parents = Query::find_candidate_parents(db, ref_candidate).await?;
|
||||
if found_parents.len() > 2 {
|
||||
if parents_details.len() > 2 {
|
||||
return Err(ServiceError::ParentOverflow);
|
||||
}
|
||||
|
||||
let found_parents = Query::find_candidate_parents(db, ref_candidate).await?;
|
||||
|
||||
let mut result = vec![];
|
||||
for i in 0..parents_details.len() {
|
||||
|
|
@ -38,6 +39,11 @@ impl ParentService {
|
|||
result.push(parent);
|
||||
}
|
||||
|
||||
// delete parents that are not in the form
|
||||
for i in parents_details.len()..found_parents.len() {
|
||||
Mutation::delete_parent(db, found_parents[i].to_owned()).await?;
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue