Skip to content

Conversation

@marcuscastelo
Copy link
Owner

This PR updates the food repository to handle Supabase duplicate EAN errors gracefully. It introduces a new utility function, isSupabaseDuplicateEanError, in the shared supabase module, along with comprehensive tests for this utility. The repository logic is updated so that when a duplicate EAN error is detected during insert or upsert, the existing food is fetched and returned instead of throwing an error.

Key changes:

  • Add isSupabaseDuplicateEanError and supporting utility to shared/supabase.
  • Add tests for the new utility.
  • Update supabaseFoodRepository to use the new utility and handle duplicate EAN errors by fetching the existing food.
  • Improves user experience and prevents unnecessary errors when inserting or upserting foods with duplicate EANs.

closes #746

…tility with tests

- Add isSupabaseDuplicateEanError utility and tests in shared/supabase
- Update supabaseFoodRepository to handle duplicate EAN error by fetching existing food
- Closes #746
Copilot AI review requested due to automatic review settings June 12, 2025 07:37
@marcuscastelo marcuscastelo self-assigned this Jun 12, 2025
@vercel
Copy link

vercel bot commented Jun 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marucs-diet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 7:38am

@github-actions github-actions bot added api API change, bug, or improvement bug Report a problem or malfunction complexity-medium Medium implementation complexity needs-investigation Requires investigation or analysis ui UI/UX related issue or improvement labels Jun 12, 2025
@marcuscastelo marcuscastelo merged commit 4683bff into rc/v0.11.0 Jun 12, 2025
8 checks passed
@marcuscastelo marcuscastelo deleted the marcuscastelo/issue746 branch June 12, 2025 07:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a utility to detect Supabase duplicate EAN errors and updates the food repository to return existing records instead of failing on duplicates.

  • Introduces isSupabaseDuplicateKeyError and isSupabaseDuplicateEanError with docs and tests.
  • Updates insertFood/upsertFood to catch duplicate EAN errors and fetch existing food.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/shared/supabase/supabaseErrorUtils.ts New utility functions for Supabase duplicate key/EAN errors
src/shared/supabase/supabaseErrorUtils.test.ts Unit tests for the duplicate EAN error detection utility
src/modules/.../supabaseFoodRepository.ts Handles duplicate EAN errors on insert/upsert to return data
Comments suppressed due to low confidence (1)

src/modules/diet/food/infrastructure/supabaseFoodRepository.ts:115

  • There are no existing tests verifying that a duplicate EAN error leads to fetching the existing record. Please add tests for insertFood/upsertFood to cover this new branch.
if (isSupabaseDuplicateEanError(error, newFood.ean)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API change, bug, or improvement bug Report a problem or malfunction complexity-medium Medium implementation complexity needs-investigation Requires investigation or analysis ui UI/UX related issue or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot scan or add EAN food due to duplicate key error

2 participants