@@ -51,6 +51,8 @@ import { getPropertiesIdsObject } from "../helper/getPropertiesIdsObject";
5151import { SharePage } from "../../enum/modals/SharePage" ;
5252import { NotionTable } from "../../enum/modals/NotionTable" ;
5353import { SendMessagePage } from "../../enum/modals/SendMessagePage" ;
54+ import { NotionUpdateRecord } from "../../enum/modals/NotionUpdateRecord" ;
55+ import { updateRecordModal } from "../modals/updateRecordModal" ;
5456
5557export class ExecuteBlockActionHandler {
5658 private context : UIKitBlockInteractionContext ;
@@ -167,6 +169,14 @@ export class ExecuteBlockActionHandler {
167169 ) ;
168170 break ;
169171 }
172+
173+ case NotionUpdateRecord . SEARCH_DB_ACTION_ID :{
174+ return this . handleSearchDbUpdateRecord (
175+ modalInteraction ,
176+ oAuth2Storage ,
177+ roomInteractionStorage
178+ )
179+ }
170180 case SendMessagePage . ACTION_ID :
171181 case SharePage . ACTION_ID : {
172182 return this . handleSelectPageAction ( ) ;
@@ -1043,4 +1053,78 @@ export class ExecuteBlockActionHandler {
10431053 errors : { } ,
10441054 } ) ;
10451055 }
1056+
1057+ private async handleSearchDbUpdateRecord (
1058+ modalInteraction : ModalInteractionStorage ,
1059+ oAuth2Storage : OAuth2Storage ,
1060+ roomInteractionStorage : RoomInteractionStorage
1061+ ) : Promise < IUIKitResponse > {
1062+ const { value, user } = this . context . getInteractionData ( ) ;
1063+
1064+ const tokenInfo = await oAuth2Storage . getCurrentWorkspace ( user . id ) ;
1065+ const roomId = await roomInteractionStorage . getInteractionRoomId ( ) ;
1066+ const room = ( await this . read . getRoomReader ( ) . getById ( roomId ) ) as IRoom ;
1067+
1068+ if ( ! tokenInfo ) {
1069+ await sendNotificationWithConnectBlock (
1070+ this . app ,
1071+ user ,
1072+ this . read ,
1073+ this . modify ,
1074+ room
1075+ ) ;
1076+
1077+ return this . context . getInteractionResponder ( ) . errorResponse ( ) ;
1078+ }
1079+
1080+ if ( ! value ) {
1081+ return this . context . getInteractionResponder ( ) . errorResponse ( ) ;
1082+ }
1083+
1084+ let Object : IDatabase = JSON . parse ( value ) ;
1085+
1086+ const database = Object as IDatabase ;
1087+
1088+ const databaseId = database . parent . database_id ;
1089+ const { NotionSdk } = this . app . getUtils ( ) ;
1090+ const { access_token } = tokenInfo ;
1091+
1092+ const properties = await NotionSdk . retrieveDatabase (
1093+ access_token ,
1094+ databaseId
1095+ ) ;
1096+
1097+ if ( properties instanceof Error ) {
1098+ this . app . getLogger ( ) . error ( properties . message ) ;
1099+ return this . context . getInteractionResponder ( ) . errorResponse ( ) ;
1100+ }
1101+
1102+ await modalInteraction . storeInputElementState (
1103+ NotionUpdateRecord . SEARCH_DB_ACTION_ID ,
1104+ properties
1105+ ) ;
1106+
1107+ await this . storeAllElements ( properties , tokenInfo , modalInteraction ) ;
1108+
1109+ const modal = await updateRecordModal (
1110+ this . app ,
1111+ user ,
1112+ this . read ,
1113+ this . persistence ,
1114+ this . modify ,
1115+ room ,
1116+ modalInteraction ,
1117+ tokenInfo ,
1118+ database
1119+ ) ;
1120+
1121+ if ( modal instanceof Error ) {
1122+ this . app . getLogger ( ) . error ( modal . message ) ;
1123+ return this . context . getInteractionResponder ( ) . errorResponse ( ) ;
1124+ }
1125+
1126+ return this . context
1127+ . getInteractionResponder ( )
1128+ . updateModalViewResponse ( modal ) ;
1129+ }
10461130}
0 commit comments