From 64f115d0d5ed398fa96734a0fe121530f98228b7 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Fri, 19 Jan 2024 16:26:28 +0100 Subject: [PATCH] fix(helloasso): handle external answer Sometimes, users import additional users in their helloasso org, for now I ignore them. --- src/helloasso.rs | 17 +++++++++++++++++ src/sync_helloasso.rs | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/helloasso.rs b/src/helloasso.rs index 9edf796..67b8623 100644 --- a/src/helloasso.rs +++ b/src/helloasso.rs @@ -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 } +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +#[fully_pub] +struct Payment { + id: u64, + + #[serde(rename = "type")] + extra: Option +} + #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[fully_pub] @@ -310,6 +325,8 @@ struct FormAnswer { #[serde(rename = "payer")] payer_user: PayerUserDetails, + payments: Vec, + order: OrderDetails, #[serde(rename = "user")] diff --git a/src/sync_helloasso.rs b/src/sync_helloasso.rs index aaa7ec1..dd7e595 100644 --- a/src/sync_helloasso.rs +++ b/src/sync_helloasso.rs @@ -86,9 +86,14 @@ pub async fn sync_helloasso(paheko_client: &paheko::AuthentifiedClient, config: let mut generalized_answers: Vec = 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())),