Skip to content

feat(farm): bulk remove plants by rarity#74

Open
kaajjaak wants to merge 1 commit into
StudyLions:mainfrom
kaajjaak:feat/farm-remove-by-rarity
Open

feat(farm): bulk remove plants by rarity#74
kaajjaak wants to merge 1 commit into
StudyLions:mainfrom
kaajjaak:feat/farm-remove-by-rarity

Conversation

@kaajjaak

Copy link
Copy Markdown

Summary

Adds a one-click way to remove all live plants of a given rarity from the farm, instead of firing one request per plot.

Server

New removeByRarity(userId, rarity) in the shared lib/pet/farmService.ts, alongside the existing waterAll/plantAll/harvestAll:

  • A single SQL CTE uproots every live, planted plot of the target rarity under FOR UPDATE and captures each plot's pre-clear gold_invested, so the 50% refund is summed from exactly the rows that were cleared — no read-then-write window, no refund drift if the farm is mutated concurrently.
  • Clear + gold credit + ledger row all commit in one transaction (all-or-nothing).
  • Dead plants are excluded, matching single-plot Remove/uprootPlot (those must be Cleared).
  • Validates rarity → PetServiceError(400) on bad input.

Wired into both transports so they can't drift:

  • pages/api/pet/farm.ts (web / NextAuth)
  • pages/api/anki/pet/farm.ts (Anki / bearer)

via action: "removeByRarity" with a rarity body field.

UI

New components/pet/farm/RemoveByRarityPanel.tsx + a "Remove by Rarity" toolbar button on /pet/farm (shown only when live plants exist):

  • Lists each rarity present with its count and estimated refund (computed exactly like the server).
  • Two-step confirm per rarity, since the action is destructive and irreversible.
  • Reuses the existing PixelButton/PixelBadge/GoldDisplay primitives and the danger ink.

Testing

  • tsc --noEmit passes (0 errors).
  • Economy logic stays server-authoritative and shares the same validated path as the rest of the farm.

Add a server-side `removeByRarity` action to the shared farm service so
clearing all plants of a given rarity is one atomic call instead of N
per-plot requests. A single CTE uproots every live, planted plot of the
target rarity under FOR UPDATE and captures each plot's pre-clear
gold_invested, so the 50% refund is summed from exactly the rows cleared
(no read-then-write race, no refund drift); the clear, gold credit, and
ledger row all commit together. Dead plants are excluded, matching the
single-plot Remove (they must be Cleared).

Wired into both transports (web NextAuth route and Anki bearer route)
and exposed in the farm UI via a new RemoveByRarityPanel with per-rarity
counts, estimated refund, and a two-step confirm.
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@kaajjaak is attempting to deploy a commit to the Ari Horesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant