(fix) serialization and typization fixed

This commit is contained in:
Rorik Star Platinum 2025-11-07 17:20:54 +03:00
parent 131ff952ca
commit 35adb141ab
4 changed files with 11 additions and 6 deletions

View file

@ -6,5 +6,5 @@ pub mod consents;
pub mod accounts; pub mod accounts;
pub mod transactions; pub mod transactions;
pub use client::{BankClient, BankingError, BankingClients}; pub use client::{BankingError, BankingClients};
pub use models::{ApiResponse, AccountData, TransactionData, ConsentResponse}; // pub use models::{ApiResponse, AccountData, TransactionData, ConsentResponse};

View file

@ -49,7 +49,7 @@ pub struct ConsentResponse {
pub consent_id: String, pub consent_id: String,
pub status: String, pub status: String,
pub message: String, pub message: String,
pub created_at: DateTime<Utc>, pub created_at: String,
pub auto_approved: bool, pub auto_approved: bool,
} }

View file

@ -5,7 +5,6 @@ mod state;
mod api; mod api;
mod auth; mod auth;
use std::net::SocketAddr;
use crate::state::AppState; use crate::state::AppState;

View file

@ -60,12 +60,18 @@ pub async fn create_consent_handler(
.await .await
.map_err(map_banking_error)?; .map_err(map_banking_error)?;
let expires_at = chrono::DateTime::parse_from_rfc3339(&consent_response.created_at)
.ok()
.map(|dt| dt.with_timezone(&chrono::Utc))
.unwrap_or_else(|| chrono::Utc::now()) // fallback to now if parse fails
+ chrono::Duration::days(365);
db::consents::store_consent( db::consents::store_consent(
&state.db_pool, &state.db_pool,
&user_id, &user_id,
bank.code(), bank.code(),
&consent_response.consent_id, &consent_response.consent_id,
consent_response.created_at + chrono::Duration::days(365), expires_at,
) )
.await .await
.map_err(|e| ( .map_err(|e| (
@ -77,7 +83,7 @@ pub async fn create_consent_handler(
StatusCode::CREATED, StatusCode::CREATED,
Json(json!({ Json(json!({
"consent_id": consent_response.consent_id, "consent_id": consent_response.consent_id,
"expires_at": consent_response.created_at + chrono::Duration::days(365), "expires_at": consent_response.created_at + &chrono::Duration::days(365).to_string(),
"status": consent_response.status, "status": consent_response.status,
"message": consent_response.message, "message": consent_response.message,
})) }))