@@ -12,7 +12,6 @@ import {
12
12
ContactTemplate ,
13
13
ContactUpdate ,
14
14
ServerError ,
15
- UpdateCallLogBody ,
16
15
} from "." ;
17
16
import { calendarEventsSchema , contactsSchema } from "../schemas" ;
18
17
import { shouldSkipCallEvent } from "../util/call-event.util" ;
@@ -652,113 +651,6 @@ export class Controller {
652
651
}
653
652
}
654
653
655
- public async createCallLogForEntities (
656
- req : BridgeRequest < CallEventWithIntegrationEntities > ,
657
- res : Response ,
658
- next : NextFunction
659
- ) : Promise < void > {
660
- const { providerConfig } = req ;
661
-
662
- try {
663
- infoLogger ( "createCallLogForEntities" , `START` , providerConfig ?. apiKey ) ;
664
-
665
- if ( ! providerConfig ) {
666
- throw new ServerError ( 400 , "Missing config parameters" ) ;
667
- }
668
-
669
- if ( ! this . adapter . createCallLogsForEntities ) {
670
- throw new ServerError ( 501 , "Creating call log is not implemented" ) ;
671
- }
672
-
673
- if ( shouldSkipCallEvent ( req . body ) ) {
674
- infoLogger (
675
- "createCallLogForEntities" ,
676
- `Skipping call log for call id ${ req . body . id } ` ,
677
- providerConfig . apiKey
678
- ) ;
679
- res . status ( 200 ) . send ( "Skipping call log" ) ;
680
- return ;
681
- }
682
-
683
- infoLogger (
684
- "createCallLogForEntities" ,
685
- `Creating call Logs…` ,
686
- providerConfig . apiKey
687
- ) ;
688
-
689
- const entitiesWithCallLogReferences =
690
- await this . adapter . createCallLogsForEntities ( providerConfig , req . body ) ;
691
-
692
- entitiesWithCallLogReferences . forEach ( ( { id, logId } ) =>
693
- infoLogger (
694
- "createCallLogForEntities" ,
695
- `CallEvent with logId ${ logId } created for id ${ id } ` ,
696
- providerConfig ?. apiKey
697
- )
698
- ) ;
699
-
700
- infoLogger ( "createCallLogForEntities" , `END` , providerConfig ?. apiKey ) ;
701
- res . status ( 200 ) . send ( entitiesWithCallLogReferences ) ;
702
- } catch ( error ) {
703
- errorLogger (
704
- "createCallLogForEntities" ,
705
- "Could not create call logs:" ,
706
- providerConfig ?. apiKey ,
707
- error || "Unknown"
708
- ) ;
709
- errorLogger (
710
- "createCallLogForEntities" ,
711
- "Entity" ,
712
- providerConfig ?. apiKey ,
713
- req . body
714
- ) ;
715
- next ( error ) ;
716
- }
717
- }
718
-
719
- public async updateCallLogForEntities (
720
- req : BridgeRequest < UpdateCallLogBody > ,
721
- res : Response ,
722
- next : NextFunction
723
- ) : Promise < void > {
724
- const { providerConfig } = req ;
725
-
726
- try {
727
- infoLogger ( "updateCallLoGForEntities" , `START` , providerConfig ?. apiKey ) ;
728
-
729
- if ( ! providerConfig ) {
730
- throw new ServerError ( 400 , "Missing config parameters" ) ;
731
- }
732
-
733
- if ( ! this . adapter . updateCallLogsForEntities ) {
734
- throw new ServerError (
735
- 501 ,
736
- "Updating call log with entities is not implemented"
737
- ) ;
738
- }
739
-
740
- infoLogger (
741
- "updateCallLogForEntities" ,
742
- `Creating call Logs…` ,
743
- providerConfig ?. apiKey
744
- ) ;
745
-
746
- const entitiesWithCallLogReferences =
747
- await this . adapter . updateCallLogsForEntities ( providerConfig , req . body ) ;
748
-
749
- infoLogger ( "updateCallLoGForEntities" , `END` , providerConfig ?. apiKey ) ;
750
- res . status ( 200 ) . send ( entitiesWithCallLogReferences ) ;
751
- } catch ( error ) {
752
- errorLogger (
753
- "updateCallLogForEntities" ,
754
- "Could not update call logs with entities:" ,
755
- providerConfig ?. apiKey ,
756
- error || "Unknown"
757
- ) ;
758
- next ( error ) ;
759
- }
760
- }
761
-
762
654
public async handleConnectedEvent (
763
655
req : BridgeRequest < unknown > ,
764
656
res : Response ,
@@ -829,6 +721,70 @@ export class Controller {
829
721
}
830
722
}
831
723
724
+ public async createOrUpdateCallLogForEntities (
725
+ req : BridgeRequest < CallEventWithIntegrationEntities > ,
726
+ res : Response ,
727
+ next : NextFunction
728
+ ) : Promise < void > {
729
+ const { providerConfig } = req ;
730
+
731
+ try {
732
+ infoLogger (
733
+ "createOrUpdateCallLogForEntities" ,
734
+ `START` ,
735
+ providerConfig ?. apiKey
736
+ ) ;
737
+
738
+ if ( ! providerConfig ) {
739
+ throw new ServerError ( 400 , "Missing config parameters" ) ;
740
+ }
741
+
742
+ if ( ! this . adapter . createOrUpdateCallLogForEntities ) {
743
+ throw new ServerError (
744
+ 501 ,
745
+ "Updating call log with entities is not implemented"
746
+ ) ;
747
+ }
748
+
749
+ if ( shouldSkipCallEvent ( req . body ) ) {
750
+ infoLogger (
751
+ "createOrUpdateCallLogForEntities" ,
752
+ `Skipping call log for call id ${ req . body . id } ` ,
753
+ providerConfig . apiKey
754
+ ) ;
755
+ res . status ( 200 ) . send ( "Skipping call log" ) ;
756
+ return ;
757
+ }
758
+
759
+ infoLogger (
760
+ "createOrUpdateCallLogForEntities" ,
761
+ `Creating and updating call Logs…` ,
762
+ providerConfig . apiKey
763
+ ) ;
764
+
765
+ const entitiesWithCallLogReferences =
766
+ await this . adapter . createOrUpdateCallLogForEntities (
767
+ providerConfig ,
768
+ req . body
769
+ ) ;
770
+
771
+ infoLogger (
772
+ "createOrUpdateCallLogForEntities" ,
773
+ `END` ,
774
+ providerConfig . apiKey
775
+ ) ;
776
+ res . status ( 200 ) . send ( entitiesWithCallLogReferences ) ;
777
+ } catch ( error ) {
778
+ errorLogger (
779
+ "createOrUpdateCallLogForEntities" ,
780
+ "Could not update call logs with entities:" ,
781
+ providerConfig ?. apiKey ,
782
+ error || "Unknown"
783
+ ) ;
784
+ next ( error ) ;
785
+ }
786
+ }
787
+
832
788
public async getEntity (
833
789
req : IntegrationEntityBridgeRequest ,
834
790
res : Response ,
0 commit comments