@@ -61,24 +61,29 @@ class SyncService {
6161
6262 handleGcalNotification = async ( payload : Payload_Sync_Notif ) => {
6363 console . log ( "++ handleGcalNotification payload:" , payload ) ;
64+ const { channelId, resourceId, resourceState } = payload ;
65+ if ( resourceState !== "exists" ) {
66+ logger . info ( `Sync initialized for channelId: ${ payload . channelId } ` ) ;
67+ return "initialized" ;
68+ }
6469
6570 // Get the sync record to find the calendar ID
66- const sync = await getSync ( { resourceId : payload . resourceId } ) ;
71+ const sync = await getSync ( { resourceId } ) ;
6772 if ( ! sync ) {
6873 throw error (
6974 SyncError . NoSyncRecordForUser ,
70- `Notification not handled because no sync record found for resource ${ payload . resourceId } ` ,
75+ `Notification not handled because no sync record found for resource ${ resourceId } ` ,
7176 ) ;
7277 }
7378
7479 // Find the calendar sync record
7580 const calendarSync = sync . google ?. events ?. find (
76- ( event ) => event . channelId === payload . channelId ,
81+ ( event ) => event . channelId === channelId ,
7782 ) ;
7883 if ( ! calendarSync ?. gCalendarId ) {
7984 throw error (
8085 SyncError . NoSyncRecordForUser ,
81- `Notification not handled because no calendar found for channel ${ payload . channelId } ` ,
86+ `Notification not handled because no calendar found for channel ${ channelId } ` ,
8287 ) ;
8388 }
8489
@@ -89,7 +94,7 @@ class SyncService {
8994 const handler = new GCalNotificationHandler ( gcal , sync . user ) ;
9095 return handler . handleNotification ( {
9196 calendarId : calendarSync . gCalendarId ,
92- resourceId : payload . resourceId ,
97+ resourceId : resourceId ,
9398 } ) ;
9499 } ;
95100
0 commit comments