mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-05 02:50:47 +00:00
feat: validate field of study so one person can't apply to two same fields
This commit is contained in:
parent
bcb43b622c
commit
2e68b33eef
1 changed files with 6 additions and 0 deletions
|
|
@ -46,6 +46,7 @@ impl ApplicationService {
|
||||||
|
|
||||||
|
|
||||||
let (candidate, enc_personal_id_number) = Self::find_or_create_candidate_with_personal_id(
|
let (candidate, enc_personal_id_number) = Self::find_or_create_candidate_with_personal_id(
|
||||||
|
application_id,
|
||||||
admin_private_key,
|
admin_private_key,
|
||||||
db,
|
db,
|
||||||
personal_id_number,
|
personal_id_number,
|
||||||
|
|
@ -67,6 +68,7 @@ impl ApplicationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn find_or_create_candidate_with_personal_id(
|
async fn find_or_create_candidate_with_personal_id(
|
||||||
|
application_id: i32,
|
||||||
admin_private_key: &String,
|
admin_private_key: &String,
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
personal_id_number: String,
|
personal_id_number: String,
|
||||||
|
|
@ -100,9 +102,13 @@ impl ApplicationService {
|
||||||
let mut linked_applications_pubkeys: Vec<String> = Query::find_applications_by_candidate_id(db, candidate.id)
|
let mut linked_applications_pubkeys: Vec<String> = Query::find_applications_by_candidate_id(db, candidate.id)
|
||||||
.await?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|a| a.id.to_string()[0..3] != application_id.to_string()[0..3])
|
||||||
.map(|a| a.public_key.to_owned())
|
.map(|a| a.public_key.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
if linked_applications_pubkeys.is_empty() {
|
||||||
|
return Err(ServiceError::InvalidApplicationId);
|
||||||
|
}
|
||||||
if linked_applications_pubkeys.len() > 1 {
|
if linked_applications_pubkeys.len() > 1 {
|
||||||
return Err(ServiceError::TooManyApplications);
|
return Err(ServiceError::TooManyApplications);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue