feat: enhance integration lookup by adding provider fallback

- Implemented a fallback mechanism in the SyncMixin to search for calendar integrations by provider name (Google/Outlook) if the integration ID is not found.
- This change addresses scenarios where frontend local IDs do not match backend IDs, improving integration handling and user experience.

All quality checks pass.
This commit is contained in:
2025-12-30 15:31:25 -05:00
parent 93369248a9
commit c017e08826

View File

@@ -68,9 +68,24 @@ class SyncMixin:
# Verify integration exists
async with self._create_repository_provider() as uow:
integration = await uow.integrations.get(integration_id)
# Fallback: if integration not found by ID, try looking up by provider name
# This handles cases where frontend uses local IDs that don't match backend
if integration is None:
await abort_not_found(context, ENTITY_INTEGRATION, request.integration_id)
return noteflow_pb2.StartIntegrationSyncResponse()
# Try to find connected calendar integration by provider (google/outlook)
for provider_name in ["google", "outlook"]:
candidate = await uow.integrations.get_by_provider(
provider=provider_name,
integration_type="calendar",
)
if candidate is not None and candidate.is_connected:
integration = candidate
integration_id = integration.id
break
if integration is None:
await abort_not_found(context, ENTITY_INTEGRATION, request.integration_id)
return noteflow_pb2.StartIntegrationSyncResponse()
provider = integration.config.get("provider") if integration.config else None
if not provider: