Skip to content

fix: don't record joins for complaints that don't exist - #227

Merged
Janani-bn merged 1 commit into
Janani-bn:mainfrom
reyhaan07:fix/join-missing-complaint
Oct 22, 2026
Merged

Janani-bn merged 1 commit into
Janani-bn:mainfrom
reyhaan07:fix/join-missing-complaint

Conversation

@reyhaan07

Copy link
Copy Markdown
Contributor

Closes #226

What was wrong

Complaint.join inserted the complaint_joins row before finding out (via the UPDATE) that the complaint didn't exist. The caller got a 404, but the orphan row later made the real complaint report "already joined" for that user or session, with no supporter counted.

Fix

Check that the complaint exists before inserting; return null (the controller's existing 404 path) if it doesn't.

Tests

New backend/tests/complaintJoin.test.js: joins an id that doesn't exist and checks that no complaint_joins row was written. Fails on main (one row found), passes with this change. npm test in backend/: 79 tests, 79 pass.

Complaint.join inserted the complaint_joins row first and only then
found out, via the UPDATE, that there was no such complaint. The caller
got a 404, but the row stayed. complaint_joins has no foreign key, so
when a complaint with that id was created later, the same user or session
was told "You have already joined this complaint" and saw it in their
joined list, while supporter_count was never incremented.

Check that the complaint exists before inserting.
@Janani-bn
Janani-bn merged commit bc8fcab into Janani-bn:main Oct 22, 2026
1 check 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.

Joining a complaint that doesn't exist leaves a join row that later blocks the real join

2 participants