Repository navigation
Feature: Normalize project name input and sanitize whitespace - #117
Conversation
WalkthroughBoth project schemas now normalize the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
||
| export const createProjectSchema = z.object({ | ||
| title: z.string().trim().min(1, { message: 'Title is required' }).max(200, { message: 'Title is too long' }), | ||
| title: z.string().trim().transform((val) => val.replace(/\s+/g, ' ')).min(1, { message: 'Title is required' }).max(200, { message: 'Title is too long' }), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "schema.prisma" -o -name "*.prisma" | head -20Repository: Authormaton/authormaton
Length of output: 89
🏁 Script executed:
cat -n ./prisma/schema.prismaRepository: Authormaton/authormaton
Length of output: 2254
🏁 Script executed:
find . -path ./node_modules -prune -o -name "*migration*" -type f -print | grep -i prismaRepository: Authormaton/authormaton
Length of output: 292
🏁 Script executed:
cat -n ./prisma/migrations/20250909132930_added_projects/migration.sqlRepository: Authormaton/authormaton
Length of output: 797
🏁 Script executed:
ls -la ./prisma/migrations/Repository: Authormaton/authormaton
Length of output: 471
🏁 Script executed:
cat -n ./prisma/migrations/20250917091926_required_user_name/migration.sqlRepository: Authormaton/authormaton
Length of output: 343
🏁 Script executed:
cd ./prisma && prisma migrate status 2>&1 || echo "Prisma CLI check completed"Repository: Authormaton/authormaton
Length of output: 138
🏁 Script executed:
rg -n "createProject" --type ts -g "!*.test.ts" -B 2 -A 5Repository: Authormaton/authormaton
Length of output: 5228
🏁 Script executed:
cat -n src/actions/projects/createProject/logic.tsRepository: Authormaton/authormaton
Length of output: 1940
🏁 Script executed:
rg -n "@@unique" src/Repository: Authormaton/authormaton
Length of output: 49
🏁 Script executed:
rg -n "project\." src/ --type ts -C 2 | grep -i "title\|findUnique\|where" | head -40Repository: Authormaton/authormaton
Length of output: 855
🏁 Script executed:
cat -n src/actions/projects/updateProject/schema.tsRepository: Authormaton/authormaton
Length of output: 307
🏁 Script executed:
cat -n src/actions/projects/updateProject/logic.tsRepository: Authormaton/authormaton
Length of output: 673
🏁 Script executed:
cat -n src/actions/projects/getProjects.ts | head -60Repository: Authormaton/authormaton
Length of output: 2002
Critical gaps prevent this change from functioning correctly.
The whitespace normalization logic is implemented correctly for new projects, but the change is incomplete and has critical issues:
-
Missing database migration: The
@@unique([userId, title])constraint is defined in schema.prisma but not yet migrated. The P2002 error handling in createProject logic cannot work until the database enforces this constraint. This must be generated and applied before deployment. -
Update route bypasses validation:
updateProject/schema.tshas no validation (title: z.string()), allowing users to bypass normalization by updating existing projects. Users could create "My Project" (normalized), then update it to "My Project", creating inconsistent data. Apply the same normalization and validation chain to updateProject schema. -
Data consistency risk: If the database constraint migration is applied to existing data containing duplicate titles that differ only in whitespace, the migration will fail. Review existing projects for duplicates before adding the constraint.
🤖 Prompt for AI Agents
In src/actions/projects/createProject/schema.ts around line 5, the title
normalization was added but three critical fixes are required: 1) generate and
apply a Prisma migration that enforces the @@unique([userId, title]) constraint
in schema.prisma before deploying so the P2002 handling in createProject will
work; 2) make updateProject/schema.ts use the identical
z.string().trim().transform(...).min(1).max(200) normalization/validation chain
so updates cannot bypass normalization; 3) before applying the migration, scan
existing projects for title duplicates that differ only by whitespace and
resolve them (merge/rename/delete) to avoid migration failure, then run the
migration and deploy.
|
this'll make project name inputs way cleaner and prevent duplicates, nice work! |
This change improves the user experience for project creation by normalizing project names and sanitizing input.
Changes:
src/actions/projects/createProject/action.tsto prevent accidental duplicate names due to varied spacing.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.