Skip to content

Commit c16a261

Browse files
committed
🐛 Fix: Handle sync init during signup
1 parent fc1b38a commit c16a261

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/backend/src/sync/services/notify/gcal.notification.handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class GCalNotificationHandler {
2323
if (!sync) {
2424
throw error(
2525
SyncError.NoSyncRecordForUser,
26-
`Notification not handled because no sync record found for calendar ${payload.calendarId}`,
26+
`Notification not handled because no sync record found for calendarId: ${payload.calendarId}`,
2727
);
2828
}
2929

@@ -34,7 +34,7 @@ export class GCalNotificationHandler {
3434
if (!calendarSync?.nextSyncToken) {
3535
throw error(
3636
SyncError.NoSyncToken,
37-
`Notification not handled because no sync token found for calendar ${payload.calendarId}`,
37+
`Notification not handled because no sync token found for calendarId: ${payload.calendarId}`,
3838
);
3939
}
4040

packages/backend/src/sync/services/sync.service.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)