Merge pull request #149 from EETagent/db_more_details

This commit is contained in:
Vojtěch Jungmann 2023-01-14 14:12:15 +01:00 committed by GitHub
commit 089c452aec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 103 additions and 36 deletions

2
.gitignore vendored
View file

@ -15,3 +15,5 @@ target/
.env
Rocket.toml

View file

@ -1,5 +0,0 @@
#[default]
#template_dir = "api/templates/"
[default.databases.sea_orm]
#url = "postgres://root:root@localhost/rocket_example"

View file

@ -298,6 +298,8 @@ mod tests {
\"email\": \"magor@magor.cz\",
\"sex\": \"MALE\",
\"personalIdNumber\": \"0101010000\",
\"schoolName\": \"29988383\",
\"healthInsurance\": \"000\",
\"study\": \"KB\"
},
\"parents\": [

View file

@ -66,22 +66,25 @@ impl Mutation {
enc_candidate: EncryptedCandidateDetails,
) -> Result<candidate::Model, sea_orm::DbErr> {
let application = user.application;
let mut user: candidate::ActiveModel = user.into();
user.name = Set(enc_candidate.name.map(|e| e.into()));
user.surname = Set(enc_candidate.surname.map(|e| e.into()));
user.birthplace = Set(enc_candidate.birthplace.map(|e| e.into()));
user.birthdate = Set(enc_candidate.birthdate.map(|e| e.into()));
user.address = Set(enc_candidate.address.map(|e| e.into()));
user.telephone = Set(enc_candidate.telephone.map(|e| e.into()));
user.citizenship = Set(enc_candidate.citizenship.map(|e| e.into()));
user.email = Set(enc_candidate.email.map(|e| e.into()));
user.sex = Set(enc_candidate.sex.map(|e| e.into()));
user.personal_identification_number = Set(enc_candidate.personal_id_number.map(|e| e.into()).unwrap_or_default()); // TODO: do not set this here, it is already set in the create_candidate mutation???
user.study = Set(enc_candidate.study.map(|e| e.into()));
let mut candidate: candidate::ActiveModel = user.into();
user.updated_at = Set(chrono::offset::Local::now().naive_local());
candidate.name = Set(enc_candidate.name.map(|e| e.into()));
candidate.surname = Set(enc_candidate.surname.map(|e| e.into()));
candidate.birthplace = Set(enc_candidate.birthplace.map(|e| e.into()));
candidate.birthdate = Set(enc_candidate.birthdate.map(|e| e.into()));
candidate.address = Set(enc_candidate.address.map(|e| e.into()));
candidate.telephone = Set(enc_candidate.telephone.map(|e| e.into()));
candidate.citizenship = Set(enc_candidate.citizenship.map(|e| e.into()));
candidate.email = Set(enc_candidate.email.map(|e| e.into()));
candidate.sex = Set(enc_candidate.sex.map(|e| e.into()));
candidate.personal_identification_number = Set(enc_candidate.personal_id_number.map(|e| e.into()).unwrap_or_default()); // TODO: do not set this here, it is already set in the create_candidate mutation???
candidate.school_name = Set(enc_candidate.school_name.map(|e| e.into()));
candidate.health_insurance = Set(enc_candidate.health_insurance.map(|e| e.into()));
candidate.study = Set(enc_candidate.study.map(|e| e.into()));
let update = user.update(db).await?;
candidate.updated_at = Set(chrono::offset::Local::now().naive_local());
let update = candidate.update(db).await?;
info!("CANDIDATE {} DETAILS UPDATED", application);

View file

@ -52,6 +52,8 @@ pub struct CandidateDetails {
pub sex: String,
pub study: String,
pub personal_id_number: String,
pub school_name: String,
pub health_insurance: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
@ -87,6 +89,8 @@ pub struct Row {
pub sex: Option<String>,
pub study: Option<String>,
pub personal_identification_number: Option<String>,
pub school_name: Option<String>,
pub health_insurance: Option<String>,
pub parent_name: Option<String>,
pub parent_surname: Option<String>,

View file

@ -24,6 +24,8 @@ pub struct EncryptedCandidateDetails {
pub email: Option<EncryptedString>,
pub sex: Option<EncryptedString>,
pub personal_id_number: Option<EncryptedString>,
pub school_name: Option<EncryptedString>,
pub health_insurance: Option<EncryptedString>,
pub study: Option<String>,
}
@ -128,6 +130,8 @@ impl EncryptedCandidateDetails {
EncryptedString::new_option(&form.email, recipients),
EncryptedString::new_option(&form.sex, recipients),
EncryptedString::new_option(&form.personal_id_number, recipients),
EncryptedString::new_option(&form.school_name, recipients),
EncryptedString::new_option(&form.health_insurance, recipients),
)?;
Ok(
@ -142,6 +146,8 @@ impl EncryptedCandidateDetails {
email: d.7,
sex: d.8,
personal_id_number: d.9,
school_name: d.10,
health_insurance: d.11,
study: Some(form.study.clone()),
}
)
@ -159,6 +165,8 @@ impl EncryptedCandidateDetails {
EncryptedString::decrypt_option(&self.email, priv_key), // 7
EncryptedString::decrypt_option(&self.sex, priv_key), // 8
EncryptedString::decrypt_option(&self.personal_id_number, priv_key),// 9
EncryptedString::decrypt_option(&self.school_name, priv_key), // 10
EncryptedString::decrypt_option(&self.health_insurance, priv_key), // 11
)?;
Ok(CandidateDetails {
@ -172,6 +180,8 @@ impl EncryptedCandidateDetails {
email: d.7.unwrap_or_default(),
sex: d.8.unwrap_or_default(),
personal_id_number: d.9.unwrap_or_default(),
school_name: d.10.unwrap_or_default(),
health_insurance: d.11.unwrap_or_default(),
study: self.study.clone().unwrap_or_default(),
}
)
@ -206,6 +216,8 @@ impl From<&candidate::Model> for EncryptedCandidateDetails {
email: EncryptedString::try_from(&candidate.email).ok(),
sex: EncryptedString::try_from(&candidate.sex).ok(),
personal_id_number: Some(EncryptedString::from(candidate.personal_identification_number.to_owned())),
school_name: EncryptedString::try_from(&candidate.school_name).ok(),
health_insurance: EncryptedString::try_from(&candidate.health_insurance).ok(),
study: candidate.study.clone(),
}
}
@ -342,6 +354,8 @@ impl TryFrom<Row> for EncryptedApplicationDetails {
email: EncryptedString::try_from(&cp.email).ok(),
sex: EncryptedString::try_from(&cp.sex).ok(),
personal_id_number: EncryptedString::try_from(&cp.personal_identification_number).ok(),
school_name: EncryptedString::try_from(&cp.school_name).ok(),
health_insurance: EncryptedString::try_from(&cp.health_insurance).ok(),
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet).ok(),
},
parents: vec![EncryptedParentDetails {
@ -394,6 +408,8 @@ pub mod tests {
email: "email".to_string(),
sex: "sex".to_string(),
personal_id_number: "personal_id_number".to_string(),
school_name: "school_name".to_string(),
health_insurance: "health_insurance".to_string(),
study: "study".to_string(),
},
parents: vec![ParentDetails {

View file

@ -71,6 +71,8 @@ mod tests {
email: "email".to_string(),
sex: "sex".to_string(),
personal_id_number: "personal_id_number".to_string(),
school_name: "school_name".to_string(),
health_insurance: "health_insurance".to_string(),
study: "study".to_string(),
},
parents: vec![ParentDetails {

View file

@ -16,6 +16,8 @@ impl From<(i32, ApplicationDetails)> for Row {
email: Some(c.email),
sex: Some(c.sex),
study: Some(c.study),
health_insurance: Some(c.health_insurance),
school_name: Some(c.school_name),
personal_identification_number: Some(c.personal_id_number),
parent_name: d.parents.get(0).map(|p| p.name.clone()),

View file

@ -20,8 +20,8 @@ pub struct Model {
pub sex: Option<String>,
pub study: Option<String>,
pub personal_identification_number: String,
#[sea_orm(column_type = "Text", nullable)]
pub personal_identification_number_hash: Option<String>,
pub school_name: Option<String>,
pub health_insurance: Option<String>,
pub public_key: String,
pub private_key: String,
pub created_at: DateTime,

View file

@ -158,8 +158,9 @@
>{$candidateData.candidate.personalIdNumber}</span
></span
>
<span>Telefon: <span class="font-bold">{$candidateData.candidate.telephone}</span></span
>
<span>IČO/Název školy: <span class="font-bold">{$candidateData.candidate.schoolName}</span></span>
<span>Číslo zdravotní pojišťovny: <span class="font-bold">{$candidateData.candidate.healthInsurance}</span></span>
<span>Telefon: <span class="font-bold">{$candidateData.candidate.telephone}</span></span>
</div>
<div
use:tippy={{

View file

@ -13,6 +13,8 @@ export interface CandidateData {
sex: string;
study: string;
personalIdNumber: string;
schoolName: string;
healthInsurance: string;
};
parents: Array<{
name: string;
@ -60,7 +62,9 @@ export const candidateData = writable<CandidateData>({
email: '',
sex: '',
study: '',
personalIdNumber: ''
personalIdNumber: '',
schoolName: '',
healthInsurance: ''
},
parents: []
});

View file

@ -18,7 +18,9 @@ export const load: PageServerLoad = async ({ fetch, params }) => {
email: '',
sex: '',
study: '',
personalIdNumber: ''
personalIdNumber: '',
schoolName: '',
healthInsurance: ''
},
parents: []
};

View file

@ -53,6 +53,8 @@
zip: '',
citizenship: '',
personalIdNumber: '',
schoolName: '',
healthInsurance: '',
study: ''
},
parents: [
@ -97,6 +99,8 @@
zip: yup.string().required(),
citizenship: yup.string().required(),
personalIdNumber: yup.string().required(),
schoolName: yup.string().required(),
healthInsurance: yup.number().required(),
study: yup.string().required()
}),
parents: yup.array().of(
@ -313,7 +317,9 @@
if (
$typedErrors['candidate']['citizenship'] ||
$typedErrors['candidate']['personalIdNumber'] ||
$typedErrors['candidate']['study']
$typedErrors['candidate']['schoolName'] ||
$typedErrors['candidate']['healthInsurance'] ||
$typedErrors['candidate']['study']
) {
return true;
}
@ -569,7 +575,7 @@
Zadejte prosím své občanství, rodné číslo, či jeho alternativu Vaší země a obor na který
se hlásíte.
</p>
<div class="flex w-full flex-row md:flex-col">
<div class="flex w-full flex-col">
<span class="field">
<SelectField
error={$typedErrors['candidate']['citizenship']}
@ -579,13 +585,39 @@
options={['Česká republika', 'Slovenská republika', 'Ukrajina', 'Jiné']}
/>
</span>
<span class="field ml-2 md:ml-0">
<TextField
on:change={handleChange}
type="text"
placeholder="Evidenční číslo přihlášky"
/>
</span>
<div class="field flex flex-row">
<span>
{#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship}
<TextField
error={$typedErrors['candidate']['schoolName']}
on:change={handleChange}
type="number"
bind:value={$form.candidate.schoolName}
placeholder="IZO školy"
/>
{:else}
<TextField
error={$typedErrors['candidate']['schoolName']}
on:change={handleChange}
type="text"
bind:value={$form.candidate.schoolName}
placeholder="Název školy"
/>
{/if}
</span>
<span>
<TextField
error={$typedErrors['candidate']['healthInsurance']}
on:change={handleChange}
type="text"
bind:value={$form.candidate.healthInsurance}
placeholder="Číslo zdravotní pojišťovny"
/>
</span>
</div>
</div>
<div class="field flex items-center justify-center">
{#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship}

View file

@ -31,7 +31,8 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Candidate::Sex).string())
.col(ColumnDef::new(Candidate::Study).string())
.col(ColumnDef::new(Candidate::PersonalIdentificationNumber).string().not_null())
.col(ColumnDef::new(Candidate::PersonalIdentificationNumberHash).text())
.col(ColumnDef::new(Candidate::SchoolName).string())
.col(ColumnDef::new(Candidate::HealthInsurance).string())
.col(ColumnDef::new(Candidate::PublicKey).string().not_null())
.col(ColumnDef::new(Candidate::PrivateKey).string().not_null())
.col(ColumnDef::new(Candidate::CreatedAt).date_time().not_null())
@ -65,7 +66,8 @@ pub enum Candidate {
Sex,
Study,
PersonalIdentificationNumber,
PersonalIdentificationNumberHash,
SchoolName,
HealthInsurance,
PublicKey,
PrivateKey,
CreatedAt,