Skip to content

fix: contact update mutation#265

Merged
KMKoushik merged 1 commit intousesend:mainfrom
vamsi4845:fix-contact-update
Oct 2, 2025
Merged

fix: contact update mutation#265
KMKoushik merged 1 commit intousesend:mainfrom
vamsi4845:fix-contact-update

Conversation

@vamsi4845
Copy link
Copy Markdown
Contributor

@vamsi4845 vamsi4845 commented Oct 2, 2025

Issue: The contactBookId was being passed to Prisma's update method as part of the data object, but it's not an updatable field, causing an "Unknown argument" error.

Fix: Destructured contactBookId out of the input(because middleware needs Id to lookup) , so only valid update fields reach Prisma

Before

chrome_wKtNAfkpRe.mp4

After

chrome_g6QwBiNiMB.mp4

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when updating contact books by sending only necessary fields, reducing the chance of update errors.
  • Refactor

    • Streamlined backend handling for contact book updates to use relevant data only, improving maintainability and consistency without changing user-facing behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

The change modifies apps/web/src/server/api/routers/contacts.ts. In the updateContactBook mutation, the input is deconstructed to extract contactBookId, and the remaining fields are passed as the update payload to the service, omitting contactBookId from the payload. Control flow and error handling are unchanged. There are no alterations to exported/public signatures.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly indicates a bug fix for the contact update mutation, which directly corresponds to the PR’s change of adjusting the update logic to exclude the non-updatable contactBookId field from the payload.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 2, 2025

@vamsi4845 is attempting to deploy a commit to the kmkoushik's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/server/api/routers/contacts.ts (1)

77-91: Replace input.contactBookId with contactBook.id

The contacts query’s input schema doesn’t include contactBookId, so input.contactBookId is always undefined. Use the loaded contactBook.id from context instead:

const whereConditions: Prisma.ContactFindManyArgs["where"] = {
-  contactBookId: input.contactBookId,
+  contactBookId: contactBook.id,
  ...(input.subscribed !== undefined
    ? { subscribed: input.subscribed }
    : {}),
  ...(input.search
    ? {
        OR: [
          { email: { contains: input.search, mode: "insensitive" } },
          { firstName: { contains: input.search, mode: "insensitive" } },
          { lastName: { contains: input.search, mode: "insensitive" } },
        ],
      }
    : {}),
};
🧹 Nitpick comments (1)
apps/web/src/server/api/routers/contacts.ts (1)

54-55: Fix correctly resolves the Prisma error.

The destructuring approach properly excludes contactBookId from the update payload, preventing the "Unknown argument" error. The pattern is consistent with the updateContact mutation (lines 148-150).

Consider removing contactBookId from the input schema (line 47) since:

  • contactBookProcedure already validates and provides contactBook in context
  • The value is never used (destructured but discarded)
  • It reduces the API surface and prevents confusion

Similar cleanup could apply to deleteContactBook (line 59).

 updateContactBook: contactBookProcedure
   .input(
     z.object({
-      contactBookId: z.string(),
       name: z.string().optional(),
       properties: z.record(z.string()).optional(),
       emoji: z.string().optional(),
     })
   )
   .mutation(async ({ ctx: { contactBook }, input }) => {
-    const { contactBookId, ...data } = input;
-    return contactBookService.updateContactBook(contactBook.id, data);
+    return contactBookService.updateContactBook(contactBook.id, input);
   }),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42849cd and 713ef4c.

📒 Files selected for processing (1)
  • apps/web/src/server/api/routers/contacts.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Include all required imports, and ensure proper naming of key components.

Files:

  • apps/web/src/server/api/routers/contacts.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript with 2-space indentation and semicolons (enforced by Prettier)
ESLint must pass with zero warnings using @usesend/eslint-config
Do not use dynamic imports (avoid import() and dynamic loading)

Files:

  • apps/web/src/server/api/routers/contacts.ts
**/*.{ts,tsx,md}

📄 CodeRabbit inference engine (AGENTS.md)

Format code and docs with Prettier 3

Files:

  • apps/web/src/server/api/routers/contacts.ts
apps/web/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/**/*.{ts,tsx}: In apps/web, use the "/" alias for src imports (e.g., import { x } from "/utils/x")
Prefer using tRPC for API calls unless explicitly instructed otherwise

Files:

  • apps/web/src/server/api/routers/contacts.ts

@KMKoushik
Copy link
Copy Markdown
Member

TYSM

@KMKoushik KMKoushik merged commit 1216b80 into usesend:main Oct 2, 2025
3 of 4 checks passed
@vamsi4845 vamsi4845 deleted the fix-contact-update branch October 3, 2025 03:06
@coderabbitai coderabbitai bot mentioned this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants