Repository navigation
feat: implement create form API, AI generate endpoint, and update for… - #62
Conversation
|
Warning Review limit reached
More reviews will be available in 40 minutes and 8 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds form type support across Prisma and API validation, persists ChangesForm API, schema, and auth updates
Database migration changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/api/src/lib/form-schemas.ts`:
- Around line 36-38: The GenerateFormSchema prompt field is currently
unrestricted, so update the zod schema in form-schemas.ts to match the existing
description pattern by trimming input and enforcing a reasonable minimum/maximum
length on prompt. Use the GenerateFormSchema object as the fix point, and keep
the prompt field optional while applying the same string normalization and size
constraints used elsewhere in the file.
- Line 17: The CreateFormSchema form type currently only accepts uppercase
values, while API clients send lowercase `scroll`, `step`, and `chat`, causing
validate() to reject valid requests. Update the schema in form-schemas.ts to
accept both case variants and normalize the parsed value to the uppercase enum
expected by Prisma, so req.body replacement in validate.ts persists a consistent
database-ready type.
In `@packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql`:
- Around line 20-25: The migration in the accounts table change drops existing
identifier columns and adds new required ones, which will break on non-empty
data and lose auth links. Update the Prisma migration to preserve existing
values by renaming/backfilling the current provider/providerAccountId/type
fields into providerId/accountId (and any equivalent target columns) inside the
same migration, then only drop the old columns after data is migrated; use the
affected account-table migration block as the fix point.
- Around line 31-32: The migration for users.emailVerified is resetting existing
verification state by dropping and re-adding the column, so update the Prisma
migration SQL to preserve current values instead of recreating the field. Use
the existing users table and the emailVerified column in this migration to
convert prior non-null values into the new BOOLEAN shape, then keep the column
with a false default only for new rows. Ensure the migration logic in the ALTER
TABLE block preserves verified users rather than forcing everyone back to
unverified.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: f5c2504d-1ecb-4675-b659-88e644533e68
📒 Files selected for processing (5)
apps/api/src/controllers/form.controller.tsapps/api/src/lib/form-schemas.tsapps/api/src/routes/form/form.routes.tspackages/db/prisma/migrations/20260625051303_add_form_type/migration.sqlpackages/db/prisma/schema/form.prisma
📜 Review details
🧰 Additional context used
🪛 SQLFluff (4.2.2)
packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql
[error] 17-17: DROP statement should use CONCURRENTLY to avoid locking the table.
(PG01)
🔇 Additional comments (4)
apps/api/src/routes/form/form.routes.ts (1)
4-12: LGTM!Also applies to: 25-25
packages/db/prisma/schema/form.prisma (1)
4-44: LGTM!Also applies to: 54-75
apps/api/src/controllers/form.controller.ts (1)
5-5: LGTM!Also applies to: 79-91, 149-160
packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql (1)
13-14: LGTM!Also applies to: 27-28
…pt schema constraints, and refine database migration logic for schema updates
…lug regex, type alias
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/api/src/controllers/form.controller.ts`:
- Around line 83-97: The write responses from createForm and updateForm are
returning the Prisma row shape instead of the external form shape, so clients
see internal fields and miss the updated definition. Update both controllers to
normalize their response the same way getForm does by selecting the stored
fields and mapping them back to definition before sending the JSON response. Use
the existing createForm, updateForm, and getForm handlers as the entry points to
keep the API response shape consistent across reads and writes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: aacc5353-ff18-49ca-a8b9-99de146b6e33
📒 Files selected for processing (4)
apps/api/src/controllers/form.controller.tsapps/api/src/lib/form-schemas.tsapps/api/src/middleware/require-auth.tspackages/db/prisma/migrations/20260625051303_add_form_type/migration.sql
📜 Review details
🧰 Additional context used
🪛 SQLFluff (4.2.2)
packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql
[error] 17-17: DROP statement should use CONCURRENTLY to avoid locking the table.
(PG01)
[error] 31-31: Unnecessary CASE statement. Use COALESCE function instead.
(ST02)
🔇 Additional comments (6)
apps/api/src/middleware/require-auth.ts (1)
15-17: LGTM!packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql (3)
17-23: LGTM!
28-36: LGTM!
25-26: LGTM!apps/api/src/lib/form-schemas.ts (1)
5-9: LGTM!Also applies to: 19-23, 42-48
apps/api/src/controllers/form.controller.ts (1)
118-143: LGTM!Also applies to: 242-248
Basharkhan7776
left a comment
There was a problem hiding this comment.
Merging the PR, will the ai implementation in future changes
Sure, happy to pick up the AI integration whenever it’s ready to be scoped |
Summary
Implemented the Create Form APIs block, allowing the client to safely create forms under an active session, define the structural format type of the form, and interface with future AI functionality.
Changes Made
FormTypeenum (SCROLL,STEP,CHAT) and added thetypecolumn to theFormmodel.POST /api/v1/formsto securely create forms under the session, mapping frontend "drag and drop snippets" correctly into thedefinitionJSON.PATCH /api/v1/forms/:idto support updating thetypeof the form post-creation.POST /api/v1/forms/generateas a placeholder logic endpoint to unblock frontend "AI Feature" development.CreateFormSchema,UpdateFormSchema,GenerateFormSchema).Testing
bun turbo lintpasses with 0 errors)Related Issues
Checklist
scroll,step,chat) and allow changing the form type after creation./forms/generateendpoint as a placeholder for future AI-based form generation.