Skip to content

feat: implement create form API, AI generate endpoint, and update for… - #62

Merged
Basharkhan7776 merged 5 commits into
Openlabsops:mainfrom
yashraj639:feature/create-form-api
Jun 27, 2026
Merged

Basharkhan7776 merged 5 commits into
Openlabsops:mainfrom
yashraj639:feature/create-form-api

Conversation

@yashraj639

@yashraj639 yashraj639 commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Updated Prisma schema to include FormType enum (SCROLL, STEP, CHAT) and added the type column to the Form model.
  • Refined POST /api/v1/forms to securely create forms under the session, mapping frontend "drag and drop snippets" correctly into the definition JSON.
  • Updated PATCH /api/v1/forms/:id to support updating the type of the form post-creation.
  • Implemented POST /api/v1/forms/generate as a placeholder logic endpoint to unblock frontend "AI Feature" development.
  • Added and updated comprehensive Zod validation schemas (CreateFormSchema, UpdateFormSchema, GenerateFormSchema).

Testing

  • Local testing and linting completed (bun turbo lint passes with 0 errors)
  • CodeRabbit issues preemptively fixed

Related Issues

Checklist

  • Code follows project conventions
  • Tests pass
  • Documentation updated
  • No linting errors
  • Enable “Create Form” within the active app session flow to ensure forms are created in the correct user context.
  • Add support for form types (scroll, step, chat) and allow changing the form type after creation.
  • Persist drag-and-drop builder snippets into the form’s definition when creating/updating.
  • Introduce a /forms/generate endpoint as a placeholder for future AI-based form generation.
  • Align create/update/generate request validation to the new API shape for consistent inputs.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@yashraj639, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 36d22fcc-6975-4dff-acee-389ec4c5c3d8

📥 Commits

Reviewing files that changed from the base of the PR and between ba94045 and 72e5a5d.

📒 Files selected for processing (1)
  • apps/api/src/controllers/form.controller.ts
📝 Walkthrough

Walkthrough

The PR adds form type support across Prisma and API validation, persists type on create and update, adds POST /api/v1/forms/generate for mocked form generation, changes the unauthorized response body, and applies the matching database migration.

Changes

Form API, schema, and auth updates

Layer / File(s) Summary
Form type contract
packages/db/prisma/schema/form.prisma, apps/api/src/lib/form-schemas.ts
The Prisma form model and create-form validation add the FormType enum and type field.
Create, read, and update forms
apps/api/src/controllers/form.controller.ts
The form controller reads typed request bodies, writes type on create and update, returns parsed definition from getForm, and narrows the publish update response.
Generate form endpoint
apps/api/src/lib/form-schemas.ts, apps/api/src/routes/form/form.routes.ts, apps/api/src/controllers/form.controller.ts
GenerateFormSchema, generateForm, and POST /generate are added to return a mocked definition from the prompt.
Unauthorized response shape
apps/api/src/middleware/require-auth.ts
Missing sessions now return { success: false, message: "Unauthorized" } with HTTP 401.

Database migration changes

Layer / File(s) Summary
Migration SQL
packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql
The migration warning header precedes SQL that creates FormType, rewrites accounts, updates forms and users, and replaces the accounts uniqueness index.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • Basharkhan7776

Possibly related PRs

  • Openlabsops/Snap-form#34: The unauthorized JSON response change in apps/api/src/middleware/require-auth.ts directly follows the middleware introduced there.
  • Openlabsops/Snap-form#38: This PR extends the Prisma form schema introduced there by adding FormType and the Form.type field.
  • Openlabsops/Snap-form#57: This PR touches the same forms validation surface and related endpoint tests as the current schema/controller updates.

Poem

A bunny hopped through schema grass,
With SCROLL, STEP, and CHAT in pass.
A prompt became a question bright,
Then forms jumped out in happy light.
🐇✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning [42] The PR covers form types and generation, but it does not show session-secured create handling or the required definition JSON/snippet mapping. Add session-aware POST /api/v1/forms handling and store snippets in the Form.definition JSON field, with create/update mapping verified.
Out of Scope Changes check ⚠️ Warning The auth middleware response-shape change and the users/accounts migration are unrelated to the create-form API scope. Move the auth/account schema changes to a separate PR unless they are required for this form feature.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly highlights the create-form APIs and AI generate endpoint, which matches the main changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between b453e4c and 9b8385c.

📒 Files selected for processing (5)
  • apps/api/src/controllers/form.controller.ts
  • apps/api/src/lib/form-schemas.ts
  • apps/api/src/routes/form/form.routes.ts
  • packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql
  • packages/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

Comment thread apps/api/src/lib/form-schemas.ts Outdated
Comment thread apps/api/src/lib/form-schemas.ts
Comment thread packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql Outdated
Comment thread packages/db/prisma/migrations/20260625051303_add_form_type/migration.sql Outdated
…pt schema constraints, and refine database migration logic for schema updates

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b8385c and ba94045.

📒 Files selected for processing (4)
  • apps/api/src/controllers/form.controller.ts
  • apps/api/src/lib/form-schemas.ts
  • apps/api/src/middleware/require-auth.ts
  • packages/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

Comment thread apps/api/src/controllers/form.controller.ts Outdated

@Basharkhan7776 Basharkhan7776 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Merging the PR, will the ai implementation in future changes

@Basharkhan7776
Basharkhan7776 merged commit 1072c70 into Openlabsops:main Jun 27, 2026
3 checks passed
@yashraj639

Copy link
Copy Markdown
Collaborator Author

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

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.

[Block] Create Form APIs

2 participants