mizuko2か月前 00Calendar Watch 通知からの データ更新フローバックエンドGoogle Calendar APIWebhookGoogle Calendar の変更通知を受信して Activity レコードを更新する処理フロー。 Webhook エンドポイントで通知受信 @Post('google') @HttpCode(HttpStatus.OK) async handleGoogleCalendarWebhook( @Headers() headers: GoogleCalendarNotificationHeaders, @Body() _body: any, ): Promise<void> { const channelId = headers['x-goog-channel-id']; const resourceState = headers['x-goog-resource-state']; if (resourceState !== 'sync') { // 非同期で同期処理を実行 setImmediate(() => { this.calendarSyncService.syncFromGoogleCalendar(channelId, resourceId) .catch(error => this.logger.error('同期エラー', error)); }); } } Activity の更新処理 private async updateDataFromEvent( event: calendar_v3.Schema$Event, data: DataEntity ): Promise<void> { const updates: Partial<DataEntity> = { name: event.summary || data.name, startDateTime: event.start?.dateTime ? new Date(event.start.dateTime) : undefined, endDateTime: event.end?.dateTime ? new Date(event.end.dateTime) : undefined, location: event.location, description: event.description }; await this.dataRepository.update(data.id, updates); } 同期ループの回避 Google Calendar 側で更新されたイベントのみ処理 自システムから更新したイベントはスキップ