@@ -621,16 +621,54 @@ fn response_to_capture_update(
621
621
response_list : HashMap < String , CaptureSyncResponse > ,
622
622
) -> RouterResult < Vec < ( storage:: Capture , storage:: CaptureUpdate ) > > {
623
623
let mut capture_update_list = vec ! [ ] ;
624
+ let mut unmapped_captures = vec ! [ ] ;
624
625
for ( connector_capture_id, capture_sync_response) in response_list {
625
626
let capture =
626
627
multiple_capture_data. get_capture_by_connector_capture_id ( connector_capture_id) ;
627
628
if let Some ( capture) = capture {
628
629
capture_update_list. push ( ( capture. clone ( ) , capture_sync_response. try_into ( ) ?) )
630
+ } else {
631
+ // connector_capture_id may not be populated in the captures table in some case
632
+ // if so, we try to map the unmapped capture response and captures in DB.
633
+ unmapped_captures. push ( capture_sync_response)
629
634
}
630
635
}
636
+ capture_update_list. extend ( get_capture_update_for_unmapped_capture_responses (
637
+ unmapped_captures,
638
+ multiple_capture_data,
639
+ ) ?) ;
640
+
631
641
Ok ( capture_update_list)
632
642
}
633
643
644
+ fn get_capture_update_for_unmapped_capture_responses (
645
+ unmapped_capture_sync_response_list : Vec < CaptureSyncResponse > ,
646
+ multiple_capture_data : & MultipleCaptureData ,
647
+ ) -> RouterResult < Vec < ( storage:: Capture , storage:: CaptureUpdate ) > > {
648
+ let mut result = Vec :: new ( ) ;
649
+ let captures_without_connector_capture_id: Vec < _ > = multiple_capture_data
650
+ . get_pending_captures_without_connector_capture_id ( )
651
+ . into_iter ( )
652
+ . cloned ( )
653
+ . collect ( ) ;
654
+ for capture_sync_response in unmapped_capture_sync_response_list {
655
+ if let Some ( capture) = captures_without_connector_capture_id
656
+ . iter ( )
657
+ . find ( |capture| {
658
+ capture_sync_response. get_connector_response_reference_id ( )
659
+ == Some ( capture. capture_id . clone ( ) )
660
+ || capture_sync_response. get_amount_captured ( ) == Some ( capture. amount )
661
+ } )
662
+ {
663
+ result. push ( (
664
+ capture. clone ( ) ,
665
+ storage:: CaptureUpdate :: try_from ( capture_sync_response) ?,
666
+ ) )
667
+ }
668
+ }
669
+ Ok ( result)
670
+ }
671
+
634
672
fn get_total_amount_captured < F : Clone , T : types:: Capturable > (
635
673
request : T ,
636
674
amount_captured : Option < i64 > ,
0 commit comments