feat(helloasso): basic list of users with custom fields
This commit is contained in:
parent
638abc06d8
commit
dd26bfa091
2 changed files with 38 additions and 23 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,3 @@
|
||||||
/target
|
/target
|
||||||
.env
|
.env
|
||||||
|
log.log
|
||||||
|
|
59
src/main.rs
59
src/main.rs
|
@ -3,6 +3,7 @@ use serde::{Serialize, Deserialize};
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow};
|
||||||
use chrono::prelude::{NaiveDate, DateTime, Utc};
|
use chrono::prelude::{NaiveDate, DateTime, Utc};
|
||||||
use strum::{Display };
|
use strum::{Display };
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
/// permanent config to store long-term config
|
/// permanent config to store long-term config
|
||||||
/// used to ingest env settings
|
/// used to ingest env settings
|
||||||
|
@ -446,35 +447,40 @@ struct CustomFieldsMapping {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// rust how to access inner enum value
|
/// rust how to access inner enum value
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
enum HelloAssoCustomFields {
|
enum HelloAssoCustomFieldType {
|
||||||
Address,
|
Address,
|
||||||
PostalCode,
|
PostalCode,
|
||||||
City,
|
City,
|
||||||
Phone,
|
Phone,
|
||||||
Job,
|
Job,
|
||||||
Skills,
|
Skills,
|
||||||
Birthday
|
Birthday,
|
||||||
|
LinkedUserFirstName
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<u64> for HelloAssoCustomFields {
|
impl TryFrom<&str> for HelloAssoCustomFieldType {
|
||||||
fn into(self) -> u64 {
|
type Error = ();
|
||||||
match self {
|
|
||||||
HelloAssoCustomFields::Address => 12958695,
|
fn try_from(subject: &str) -> Result<Self, Self::Error> {
|
||||||
HelloAssoCustomFields::PostalCode => 12958717,
|
match subject {
|
||||||
HelloAssoCustomFields::City => 12958722,
|
"Prénom conjoint" => Ok(HelloAssoCustomFieldType::LinkedUserFirstName),
|
||||||
HelloAssoCustomFields::Phone => 13279172,
|
"ADRESSE" => Ok(HelloAssoCustomFieldType::Address),
|
||||||
HelloAssoCustomFields::Job => 13279172,
|
"CODE POSTAL" => Ok(HelloAssoCustomFieldType::PostalCode),
|
||||||
HelloAssoCustomFields::Skills => 11231129,
|
"VILLE" => Ok(HelloAssoCustomFieldType::City),
|
||||||
HelloAssoCustomFields::Birthday => 12944367
|
"PROFESSION" => Ok(HelloAssoCustomFieldType::Job),
|
||||||
|
"TÉLÉPHONE" => Ok(HelloAssoCustomFieldType::Phone),
|
||||||
|
"DATE DE NAISSANCE" => Ok(HelloAssoCustomFieldType::Birthday),
|
||||||
|
"CENTRE D'INTÉRÊTS / COMPÉTENCES" => Ok(HelloAssoCustomFieldType::Skills),
|
||||||
|
_ => Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_custom_field(form_answer: &FormAnswer, custom_field_id: HelloAssoCustomFields) -> Option<String> {
|
fn read_custom_field(form_answer: &FormAnswer, custom_field: HelloAssoCustomFieldType) -> Option<String> {
|
||||||
let int_repr: u64 = custom_field_id.into();
|
// FIXME: compute the type directly at deserialization with serde
|
||||||
form_answer.custom_fields.iter()
|
form_answer.custom_fields.iter()
|
||||||
.find(|f| f.id == int_repr)
|
.find(|f| HelloAssoCustomFieldType::try_from(f.name.as_str()) == Ok(custom_field))
|
||||||
.and_then(|cf| Some(cf.answer.clone()))
|
.and_then(|cf| Some(cf.answer.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,24 +513,33 @@ async fn launch_adapter() -> Result<()> {
|
||||||
let pk_memberships: Vec<PahekoMembership> = vec![];
|
let pk_memberships: Vec<PahekoMembership> = vec![];
|
||||||
let mut pk_users: Vec<PahekoUser> = vec![];
|
let mut pk_users: Vec<PahekoUser> = vec![];
|
||||||
|
|
||||||
|
let mut count: u64 = 0;
|
||||||
|
let mut names: HashSet<String> = HashSet::new();
|
||||||
for answer in answers {
|
for answer in answers {
|
||||||
// TODO: parse birthday
|
// TODO: parse birthday
|
||||||
// NaiveDate::parse_from_str
|
// NaiveDate::parse_from_str
|
||||||
dbg!(&answer);
|
dbg!(&answer);
|
||||||
|
for custom_field in answer.custom_fields.iter() {
|
||||||
|
names.insert(custom_field.name.clone());
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
pk_users.push(PahekoUser {
|
pk_users.push(PahekoUser {
|
||||||
first_name: answer.user.first_name.clone(),
|
first_name: answer.user.first_name.clone(),
|
||||||
last_name: answer.user.last_name.clone(),
|
last_name: answer.user.last_name.clone(),
|
||||||
email: answer.user.email.clone(),
|
email: answer.user.email.clone(),
|
||||||
phone: read_custom_field(&answer, HelloAssoCustomFields::Phone),
|
phone: read_custom_field(&answer, HelloAssoCustomFieldType::Phone),
|
||||||
skills: read_custom_field(&answer, HelloAssoCustomFields::Skills),
|
skills: read_custom_field(&answer, HelloAssoCustomFieldType::Skills),
|
||||||
address: read_custom_field(&answer, HelloAssoCustomFields::Address).expect("to have address"),
|
address: read_custom_field(&answer, HelloAssoCustomFieldType::Address).expect("to have address"),
|
||||||
postal_code: read_custom_field(&answer, HelloAssoCustomFields::PostalCode).expect("to have address"),
|
postal_code: read_custom_field(&answer, HelloAssoCustomFieldType::PostalCode).expect("to have postal code"),
|
||||||
city: read_custom_field(&answer, HelloAssoCustomFields::City).expect("to have address"),
|
city: read_custom_field(&answer, HelloAssoCustomFieldType::City).expect("to have city"),
|
||||||
job: read_custom_field(&answer, HelloAssoCustomFields::Job),
|
job: read_custom_field(&answer, HelloAssoCustomFieldType::Job),
|
||||||
birthday: None
|
birthday: None
|
||||||
});
|
});
|
||||||
|
// then create optional linked user
|
||||||
}
|
}
|
||||||
dbg!(pk_users);
|
dbg!(pk_users);
|
||||||
|
dbg!(names);
|
||||||
|
dbg!(count);
|
||||||
|
|
||||||
// then, request the current list of users
|
// then, request the current list of users
|
||||||
// then, upload the PahekoMembership
|
// then, upload the PahekoMembership
|
||||||
|
|
Loading…
Reference in a new issue