fix(helloasso): handle external answer

Sometimes, users import additional users in their helloasso org, for now
I ignore them.
This commit is contained in:
Matthieu Bessat 2024-01-19 16:26:28 +01:00
parent 54bd32d57d
commit 64f115d0d5
2 changed files with 24 additions and 2 deletions

View file

@ -174,11 +174,16 @@ struct CustomFieldAnswer {
// missing type, it's probably always TextInput, if not, serde will fail to parse
}
fn default_country() -> String {
"FRA".to_string()
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[fully_pub]
struct PayerUserDetails {
#[serde(default = "default_country")]
country: String,
email: String,
first_name: String,
@ -298,6 +303,16 @@ struct OrderDetails {
inception_time: DateTime<Utc>
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[fully_pub]
struct Payment {
id: u64,
#[serde(rename = "type")]
extra: Option<String>
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[fully_pub]
@ -310,6 +325,8 @@ struct FormAnswer {
#[serde(rename = "payer")]
payer_user: PayerUserDetails,
payments: Vec<Payment>,
order: OrderDetails,
#[serde(rename = "user")]

View file

@ -86,9 +86,14 @@ pub async fn sync_helloasso(paheko_client: &paheko::AuthentifiedClient, config:
let mut generalized_answers: Vec<GeneralizedAnswer> = vec![];
for answer in answers {
// eprintln!("Processing answer:");
let email = choose_email(&answer);
// eprintln!(" email: {:?}", email);
// skip answers that were imported later and are stranger from helloasso
if let Some(payment) = answer.payments.iter().nth(0) {
if payment.extra == Some("Offline".to_string()) {
continue;
}
}
let mut generalized_answer = GeneralizedAnswer {
first_name: Some(normalize_str(answer.user.first_name.clone())),