Skip to content

Conversation

@GabrielTozatti
Copy link
Collaborator

Description

Enforces unique name validation for vaults/predicates in the API.
Previously, this check was only performed on the front-end, allowing edits to succeed with duplicate names in scenarios with slow internet or multiple quick clicks. Now, the API returns a BadRequest when a duplicate name is detected, ensuring data integrity.

Summary

  • Implemented unique name validation on the API when creating or updating a predicate/vault.
  • Throws BadRequest if the name already exists in the corresponding workspace.
  • Updated the create() method in PredicateService to properly handle expected errors versus internal errors.
  • Ensures the API blocks creation or updates of duplicate names, regardless of front-end state.

Checklist

  • I reviewed my PR code before submitting
  • I ensured that the implementation is working correctly and did not impact other parts of the app
  • I mentioned the PR link in the task

Copy link
Member

@guimroque guimroque left a comment

Choose a reason for hiding this comment

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

Code Review - Summary

What was done

Implemented server-side validation to prevent duplicate vault/predicate names within a workspace. Added a validateUniqueName method that checks for existing predicates with the same name (case-insensitive) and throws a BadRequest error if duplicates are found.

Positive Points

  • ✅ Addresses a real data integrity issue by moving validation from client to server
  • ✅ Uses case-insensitive comparison for better UX
  • ✅ Properly excludes soft-deleted records with deletedAt IS NULL
  • ✅ Returns meaningful error messages with context
  • ✅ Follows existing error handling patterns with GeneralError types

Issues Found

  • 🔴 CRITICAL: Missing validation on update operations - only validates on create
  • 🟡 IMPORTANT: Import statement formatting inconsistency
  • 🟡 IMPORTANT: Console.log should be replaced with proper logging
  • 🔵 SUGGESTION: Method could be made static for better reusability

Total comments: 4 (1 critical, 2 important, 1 suggestion)

@GabrielTozatti GabrielTozatti requested review from guimroque and removed request for guimroque January 16, 2026 20:23
Copy link
Member

@guimroque guimroque left a comment

Choose a reason for hiding this comment

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

LGTM! ✅

Previous issues have been fixed. Code approved.

@GabrielTozatti GabrielTozatti merged commit f3d6fe6 into staging Jan 16, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants