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
|
||||
.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 chrono::prelude::{NaiveDate, DateTime, Utc};
|
||||
use strum::{Display };
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// permanent config to store long-term config
|
||||
/// used to ingest env settings
|
||||
|
@ -446,35 +447,40 @@ struct CustomFieldsMapping {
|
|||
}
|
||||
|
||||
/// rust how to access inner enum value
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum HelloAssoCustomFields {
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
enum HelloAssoCustomFieldType {
|
||||
Address,
|
||||
PostalCode,
|
||||
City,
|
||||
Phone,
|
||||
Job,
|
||||
Skills,
|
||||
Birthday
|
||||
Birthday,
|
||||
LinkedUserFirstName
|
||||
}
|
||||
|
||||
impl Into<u64> for HelloAssoCustomFields {
|
||||
fn into(self) -> u64 {
|
||||
match self {
|
||||
HelloAssoCustomFields::Address => 12958695,
|
||||
HelloAssoCustomFields::PostalCode => 12958717,
|
||||
HelloAssoCustomFields::City => 12958722,
|
||||
HelloAssoCustomFields::Phone => 13279172,
|
||||
HelloAssoCustomFields::Job => 13279172,
|
||||
HelloAssoCustomFields::Skills => 11231129,
|
||||
HelloAssoCustomFields::Birthday => 12944367
|
||||
impl TryFrom<&str> for HelloAssoCustomFieldType {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(subject: &str) -> Result<Self, Self::Error> {
|
||||
match subject {
|
||||
"Prénom conjoint" => Ok(HelloAssoCustomFieldType::LinkedUserFirstName),
|
||||
"ADRESSE" => Ok(HelloAssoCustomFieldType::Address),
|
||||
"CODE POSTAL" => Ok(HelloAssoCustomFieldType::PostalCode),
|
||||
"VILLE" => Ok(HelloAssoCustomFieldType::City),
|
||||
"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> {
|
||||
let int_repr: u64 = custom_field_id.into();
|
||||
fn read_custom_field(form_answer: &FormAnswer, custom_field: HelloAssoCustomFieldType) -> Option<String> {
|
||||
// FIXME: compute the type directly at deserialization with serde
|
||||
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()))
|
||||
}
|
||||
|
||||
|
@ -507,24 +513,33 @@ async fn launch_adapter() -> Result<()> {
|
|||
let pk_memberships: Vec<PahekoMembership> = vec![];
|
||||
let mut pk_users: Vec<PahekoUser> = vec![];
|
||||
|
||||
let mut count: u64 = 0;
|
||||
let mut names: HashSet<String> = HashSet::new();
|
||||
for answer in answers {
|
||||
// TODO: parse birthday
|
||||
// NaiveDate::parse_from_str
|
||||
dbg!(&answer);
|
||||
for custom_field in answer.custom_fields.iter() {
|
||||
names.insert(custom_field.name.clone());
|
||||
count += 1;
|
||||
}
|
||||
pk_users.push(PahekoUser {
|
||||
first_name: answer.user.first_name.clone(),
|
||||
last_name: answer.user.last_name.clone(),
|
||||
email: answer.user.email.clone(),
|
||||
phone: read_custom_field(&answer, HelloAssoCustomFields::Phone),
|
||||
skills: read_custom_field(&answer, HelloAssoCustomFields::Skills),
|
||||
address: read_custom_field(&answer, HelloAssoCustomFields::Address).expect("to have address"),
|
||||
postal_code: read_custom_field(&answer, HelloAssoCustomFields::PostalCode).expect("to have address"),
|
||||
city: read_custom_field(&answer, HelloAssoCustomFields::City).expect("to have address"),
|
||||
job: read_custom_field(&answer, HelloAssoCustomFields::Job),
|
||||
phone: read_custom_field(&answer, HelloAssoCustomFieldType::Phone),
|
||||
skills: read_custom_field(&answer, HelloAssoCustomFieldType::Skills),
|
||||
address: read_custom_field(&answer, HelloAssoCustomFieldType::Address).expect("to have address"),
|
||||
postal_code: read_custom_field(&answer, HelloAssoCustomFieldType::PostalCode).expect("to have postal code"),
|
||||
city: read_custom_field(&answer, HelloAssoCustomFieldType::City).expect("to have city"),
|
||||
job: read_custom_field(&answer, HelloAssoCustomFieldType::Job),
|
||||
birthday: None
|
||||
});
|
||||
// then create optional linked user
|
||||
}
|
||||
dbg!(pk_users);
|
||||
dbg!(names);
|
||||
dbg!(count);
|
||||
|
||||
// then, request the current list of users
|
||||
// then, upload the PahekoMembership
|
||||
|
|
Loading…
Reference in a new issue