fix: auto-promote next card as default when default card is deleted#191
Open
anusuyasri wants to merge 2 commits into
Open
fix: auto-promote next card as default when default card is deleted#191anusuyasri wants to merge 2 commits into
anusuyasri wants to merge 2 commits into
Conversation
Author
|
Also please add the gssoc labels after merge,thank you! |
Collaborator
Please check our Discord channel linked in the README for a better understanding of how GSSoC labels are assigned. |
Harxhit
reviewed
May 20, 2026
| } | ||
| } | ||
|
|
||
| return reply.status(204).send(); |
Collaborator
There was a problem hiding this comment.
Error handling for DB logic can be better.
Author
There was a problem hiding this comment.
Thanks for the feedback, I've wrapped the DB logic in a try/catch block and return a 500 with a descriptive error message if anything fails.
Harxhit
reviewed
May 20, 2026
| orderBy: { createdAt: 'asc' }, | ||
| }); | ||
|
|
||
| if (nextCard) { |
Collaborator
|
@anusuyasri We wrap db logic in try catch so we can do better error handling. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the DELETE /:id card endpoint which had no logic to handle deletion of the default card. When a user deleted their default card, no other card was promoted — leaving them with no default card and breaking QR code sharing. This PR adds auto-promotion logic so the next oldest card is automatically set as default.
Closes #170
Type of Change
What Changed
How to Test
1.Create two cards for a user — set one as default
2.Send DELETE /cards/:id for the default card
3.Verify the remaining card is now automatically marked as isDefault: true
4.Repeat with only one card — verify deletion succeeds with no errors
Checklist
pnpm -r run lintpasses).pnpm -r run typecheck).pnpm -r run test).console.logor debug statements left in the code.Screenshots / Recordings
N/A backend change logic
Additional Context
The fix uses the same Prisma patterns already established in the codebase. The existing variable (already fetched before deletion for the 404 check) is reused to check isDefault, so no extra DB query is added before the delete.