fix(pub): persist published document like cancellation (#59) - #70
waterbro-8 wants to merge 2 commits into
Conversation
waterbro-8
left a comment
There was a problem hiding this comment.
Review
CI: test, docker-build, Dependency review, Scorecard pass.
This matches #59. The decrease path actually writes, clamps at zero, and stops returning success for a missing publication. Tests cover persist, nonnegative duplicate cancel, not-found, and error redaction.
Notes (non-blocking)
- The button still decrements the UI before the request. If decrease fails, the count stays low until reload. Worth a follow-up rollback, not a merge blocker for this bug.
- Like identity is still
localStorage. That is called out and tracked in #72.
Verdict: approve for merge once a CODEOWNER who is not the author signs off (repo requires last-push approval).
|
Follow-up: published like button rolls back count, liked state, and localStorage if increase/decrease fails. Head: |
Bindy-lbb
left a comment
There was a problem hiding this comment.
LGTM. The decrease endpoint now actually persists the decrement with a nonnegative clamp via updateMany with gt: 0, and missing publications correctly return an error instead of a false success. The component-level rollback on failure (count + liked state + localStorage) is clean. Good test coverage across the API (including the storage-error leak guard) and the button rollback path. Ship it.
Uncomment and complete the thumb-up decrease write so cancelling a like survives reload. Clamp at zero, return not-found instead of a false success, and cover the persisted readback path. Closes bytefolk#59
Keep the optimistic count, but restore the previous liked state and localStorage flag if increase or decrease returns an error.
78c1e36 to
3f6cda0
Compare
|
Rebased onto |
sun-970
left a comment
There was a problem hiding this comment.
Review — Approve (merge blocked on rebase)
Head 3f6cda0. CI test / docker-build / dependency review / Scorecard green.
The #59 bug is actually fixed: updateMany with thumbUpCount.gt: 0 writes the decrement, missing publications return an error instead of a false success, duplicate cancel at zero is a no-op. Button rolls back count / liked / localStorage on increase or decrease failure. Tests cover persist, nonnegative clamp, 404, error redaction, and cancel-failure rollback. Errors do not leak storage details.
Merge blocker
mergeable: CONFLICTING / DIRTY against current main. Do not merge until rebase + CI re-green.
Non-blocking
- Like identity is still
localStorage(tracked in #72). - No rate limit on public like endpoints (called out in the PR).
Summary
Closes #59.
Cancelling a like on a published document reported success and updated the UI, but the decrease endpoint returned success without writing. Reload restored the higher count.
Changes
PATCH /api/pub/thumb-up-decrease/[publishId]now decrementsthumbUpCountwhen it is greater than zero.localStorage); this PR does not add per-user like records.Test plan
npx vitest run src/__tests__/api/thumb-up-routes.test.ts(5 tests)Out of scope