Skip to content

fix(api): use @repo/db for Prisma types and resolve schema generation… - #88

Merged
Basharkhan7776 merged 2 commits into
Openlabsops:mainfrom
yashraj639:fix/template-prisma-mismatch
Jul 7, 2026
Merged

Basharkhan7776 merged 2 commits into
Openlabsops:mainfrom
yashraj639:fix/template-prisma-mismatch

Conversation

@yashraj639

@yashraj639 yashraj639 commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix TypeScript compilation errors in template controller caused by Prisma schema mismatch. The Prisma client types were referencing models and fields that existed in the schema files but had not been generated.

Changes Made

  • Updated @prisma/client imports to @repo/db in 3 controllers (template.controller.ts, form.controller.ts, response.controller.ts) for consistent dependency resolution
  • Fixed unknown error type handling in catch blocks in form.controller.ts and onboarding.controller.ts — replaced instanceof Prisma.PrismaClientKnownRequestError with runtime type guards
  • Added explicit RequestHandler type annotation to oauthCallback in oauth.controller.ts to fix inferred type portability errors
  • Regenerated Prisma client types to match schema definitions

Testing

  • All tests pass: 9/9, 0 failures, 47 expect calls
  • TypeScript compilation clean: tsc --noEmit exits with 0 errors
  • Manual testing completed
  • No regressions introduced

Related Issues

Checklist

  • Code follows project conventions
  • Tests pass
  • Documentation updated
  • No linting errors
  • Fixed API compilation issues caused by Prisma schema/client mismatches.
  • Updated form, template, and response handling to use the shared database client consistently.
  • Improved API error handling so common validation and missing-record cases are handled more reliably.
  • Made OAuth callback typing explicit to avoid type portability problems.
  • Regenerated Prisma client types to match the current schema and keep generated types in sync.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 reviews.

How do review 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 refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f366b1ed-50bc-4328-bdd3-3c5d27c706a5

📥 Commits

Reviewing files that changed from the base of the PR and between 22286bf and 6234475.

📒 Files selected for processing (3)
  • apps/api/src/controllers/form.controller.ts
  • apps/api/src/controllers/onboarding.controller.ts
  • apps/api/src/utils/prisma.ts
📝 Walkthrough

Walkthrough

This PR migrates Prisma imports from @prisma/client to @repo/db across several controllers and replaces instanceof PrismaClientKnownRequestError error checks with structural checks on err.code. It also adds a RequestHandler type annotation to the oauth controller's exported handler.

Changes

Prisma import and error handling migration

Layer / File(s) Summary
Form controller Prisma import and error handling
apps/api/src/controllers/form.controller.ts
Import switched to @repo/db; createForm, updateForm, and disconnectGoogleSheets catch blocks replace instanceof checks with structural err.code checks for P2002/P2025; minor formatting adjustments in getForm and updateForm.
Onboarding controller error handling update
apps/api/src/controllers/onboarding.controller.ts
completeOnboarding's catch block casts the error to an object with optional code and checks err.code === "P2002" instead of using optional chaining.
Prisma import updates and oauth typing
apps/api/src/controllers/response.controller.ts, apps/api/src/controllers/template.controller.ts, apps/api/src/controllers/oauth.controller.ts
Prisma imports switched to @repo/db in response and template controllers; oauthCallback is now typed as RequestHandler.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: Basharkhan7776

Poem

A rabbit hopped through code so neat,
Swapped old imports for @repo/db's beat,
No more instanceof, just err.code's grace,
Structural checks now find their place,
Hop, hop, hooray — a cleaner chase! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: switching Prisma type imports to @repo/db and fixing schema-generation-related type issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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: 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 106-109: The Prisma error-code guard is duplicated in
form.controller.ts and should be centralized into a shared typed helper. Create
and use a reusable helper like isPrismaErrorCode(err, code) that encapsulates
the object/code check, then replace each repeated P2002/P2003-style guard in the
relevant controller methods with that helper to keep the logic consistent and
reduce duplication; also update the similar guard in onboarding.controller.ts to
use the same helper.
🪄 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: 6a5870e6-51f1-48f9-b80f-bec18e18285e

📥 Commits

Reviewing files that changed from the base of the PR and between 6d5159d and 22286bf.

📒 Files selected for processing (5)
  • apps/api/src/controllers/form.controller.ts
  • apps/api/src/controllers/oauth.controller.ts
  • apps/api/src/controllers/onboarding.controller.ts
  • apps/api/src/controllers/response.controller.ts
  • apps/api/src/controllers/template.controller.ts
📜 Review details
🔇 Additional comments (5)
apps/api/src/controllers/form.controller.ts (1)

1-1: LGTM!

Also applies to: 106-109, 129-129, 170-170, 218-224, 407-410

apps/api/src/controllers/onboarding.controller.ts (1)

49-52: 🩺 Stability & Availability | ⚡ Quick win

Guard against non-object thrown values before accessing .code.

Unlike the equivalent checks added in form.controller.ts (which verify typeof err === "object" && "code" in err first), this cast skips the runtime guard. If a non-object value (e.g. null) were ever thrown here, err.code would throw and mask the original error.

🛡️ Suggested fix
     } catch (error) {
       // Unique constraint on username — can happen under concurrent requests
-      const err = error as { code?: string };
-      if (err.code === "P2002") {
+      if (error && typeof error === "object" && "code" in error && error.code === "P2002") {
         res.status(409).json({ success: false, message: "Username is already taken" });
         return;
       }
-      throw err;
+      throw error;
     }
apps/api/src/controllers/response.controller.ts (1)

4-4: LGTM!

apps/api/src/controllers/template.controller.ts (1)

1-1: LGTM!

apps/api/src/controllers/oauth.controller.ts (1)

5-7: LGTM!

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.

Good work, clear.

@Basharkhan7776
Basharkhan7776 merged commit 0d14509 into Openlabsops:main Jul 7, 2026
3 checks passed
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.

2 participants