Commit Graph
20 Commits
Author SHA1 Message Date
GandClaude Opus 5 c65ac4b7d7 chore: add a formatter (#71)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (252 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 10:05:01 +00:00
GandClaude Opus 5 37b1f59ed7 feat(shop): sell to visitors who don't have an account (#50)
The public storefront was a brochure. It shipped a Product/Offer JSON-LD so
search engines treat it as purchasable, then the only buy path was
"Sign up to buy" -> /register?returnTo=/portal/shop, which both forced
registration before a first purchase and dropped the product the visitor came
for. Cold traffic could not buy anything.

A visitor can now add to cart on the catalogue and the product page, check out
in one page with an email and an address, and read their order back from a
receipt link. No account anywhere in that path.

orders.userId becomes nullable, alongside guestEmail and an unguessable
publicToken. A CHECK constraint enforces exactly one of userId / guestEmail,
because an order with no reachable buyer cannot be repaired after the fact.
The token is the guest's only handle on their order: it is emailed, never
listed, and authorises resuming payment and cancelling while pending.

Order placement moves to placeOrder() in lib/domain/orders.ts so the authed
cart and the guest checkout share one implementation -- the stock reservation
and its compensation must not exist twice. setOrderStatus() joins it for the
same reason: a cancellation that forgot to restore stock destroys inventory,
and that happens when one route remembers and another does not.

Two joins were fixed before any UI existed. app/api/orders/seller and
app/api/admin/orders inner-joined users on orders.userId; with a nullable
column that drops every guest order from the views of the people who have to
ship them -- real revenue, invisible, nothing appearing broken. Both are now
leftJoin + COALESCE onto the address the buyer typed.

Also fixed while reviewing:
- toLocale() used `value in LOCALE_CONFIG`, true for inherited keys like
  "constructor", and the result goes straight into a URL path.
- orderShippingSchema accepted any two letters as a country, so "XX" could be
  stored and printed on an undeliverable label. Checked against a new ISO-3166
  SSOT whose names come from Intl.DisplayNames, so all nine locales are
  translated with no message files to maintain.
- Guest input (shippingName, notes) reaches a seller's inbox unauthenticated;
  email templates now escape it.

Guards, not just fixes: locale parity across all nine message files is now a
test rather than a convention, and the prod walkthrough places a real guest
order and asserts the seller can see the buyer's email -- the check that goes
red if anyone reintroduces an inner join there.

The public endpoints are deliberately outside PRIVATE_API_PREFIXES; a session
guard there would silently delete the feature. They are rate limited per
client, and the payment and cancel routes require the order token.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 08:56:48 +00:00
GandClaude Opus 5 c2b5f392c1 fix(blog): a taken URL is a 409 the author can fix, not a 500 (#49)
Caught by exercising the live endpoint as an admin rather than trusting the
unit test: creating a second post with an existing slug answered 500.

Drizzle wraps driver errors, so the pg error carrying `code: 23505` is the
`cause` of what the route catches, not the error itself. Reading only the
top-level `code` looks correct in a test — where the error is hand-built with
the code right on it — and is wrong against a real database. The test passed
and production returned 500 for a mistake the author can fix in two seconds.

isUniqueViolation now walks the cause chain, bounded, with a guard against a
self-referencing chain hanging the request.

Both tests now use the wrapped shape production actually throws, which is the
point: the old test asserted the shape I assumed, not the shape reality
produces.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 13:13:11 +00:00
GandClaude Opus 5 cd591aef27 feat(blog): publish posts from the admin instead of editing code (#48)
Publishing meant editing a TypeScript array in lib/content/blog.ts, opening a
PR, and waiting for a deploy. That is not a blog anyone will actually write in —
and it made every post a developer task. There was exactly one post.

Posts now live in the database, written and published at /admin/blog. A post
goes live the moment it is published; nothing is rebuilt or redeployed.

Authoring markup is a deliberately tiny subset of Markdown:

    ## Subheading
    - bullet
    anything else is a paragraph

No Markdown dependency. A full parser would buy inline HTML we would then have
to sanitise — an XSS surface in exchange for syntax nobody asked for. Parsing
to the closed block set the post page already styles means untrusted text can
never become markup, which a test pins with a <script> tag rendering as literal
text. The editor previews the parsed blocks live, so a mistyped bullet is
visible before publishing rather than after.

Body is stored as written and parsed at render, so the author's source stays
the single truth and the renderer can improve without a data migration.

Publish dates are stamped once, on the first publish, and preserved after that.
Unpublishing to fix a typo and publishing again must not silently re-date the
post and reshuffle the index — tested in both directions.

Drafts 404 publicly rather than merely being unlisted, so guessing a slug does
not reveal unpublished writing.

The migration carries the existing post across. Its URL
(/[locale]/blog/a-platform-for-both-sides-of-pet-care) is already public, so
losing the row would 404 an indexed page; the insert is dollar-quoted for the
apostrophes and ON CONFLICT DO NOTHING so it is safe to re-run.

Deleting is a two-step inline confirm rather than a confirm() dialog: deleting a
published post breaks its URL, and a browser dialog is both easy to click
through and impossible to drive from a test.

Both public pages are force-dynamic — content that an editor changes must not be
frozen into the build.

The walkthrough now fetches a real post and asserts its prose, which exercises
the table, the content migration and the renderer together. It fetches the body
itself rather than reading $LAST_BODY, which page() never sets — asserting on it
would have grepped whatever the previous request happened to leave behind.

27 new tests; pnpm verify green (678 tests / 75 files).

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 14:59:57 +02:00
GandClaude Opus 5 42bcc47ff4 feat(marketplace): real onboarding replaces fake profiles; orders become shippable (#33)
Three things made the marketplace a demo rather than a business.

1. Orders had no delivery address. A seller could receive an order and have
   nowhere to send it. Orders now carry a required address (migration 0004,
   additive); the API rejects an order without one, and both the seller and
   admin order views expose it so fulfilment is actually possible.

2. The directory was populated by five invented businesses. Dr. Brunner,
   Sam Keller, Nadia Roth, Pfoten & Co. and Tierheim Sonnenhof do not exist —
   a customer in Zurich searching for a groomer would have found a fiction.
   They are removed from lib/config/resident-pet.ts, and ensureCommunity is
   gone from the resident-checkin cron so nothing recreates them.

3. Nothing replaced them. lib/domain/profile-readiness.ts is now the single
   rule for when a professional or seller is real enough to be listed:
   identity, services, price, location, a 40-character intro, contact, and
   the pro's own "accepting clients" switch. The same predicate drives the
   ProfileReadiness checklist the pro sees and the SQL conditions the public
   directory queries use — so the listing is earned, never hand-curated.

Selling was already open to any account (products.sellerId = userId) but was
undiscoverable; /portal/become-a-pro now says so and links to the store setup,
which shows the seller's own readiness checklist including "list your first
product".

Also: deleting a pet was reachable only by guessing it lived inside the edit
form — the pet profile now links straight to the danger zone. Professionals
could not accept a booking from /portal/bookings, and groomers were missing
from the booking role union entirely.

E2E gains two checks: an order without an address must be rejected, and the
seller must be able to see where to ship.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-14 01:10:42 +00:00
GandClaude Fable 5 2a46bced71 fix(orders): cancelled orders restore stock; sellers can delete their account (#29)
Found by an exhaustive 129-check production walkthrough of every user path:

1. Cancelling an order never released the stock it reserved at creation —
   every cancellation permanently destroyed inventory. Cancellation (user
   or admin) now restores stock for finite-stock items, guarded against
   double-restore.

2. A seller who had ever sold anything could not delete their account
   (GDPR erasure 500'd): order_items.product_id was ON DELETE RESTRICT.
   Order items now snapshot the product NAME at purchase time (they
   already snapshot price), product_id is nullable ON DELETE SET NULL,
   and all order reads use the snapshot — the buyer's order history
   survives the seller's erasure intact. Migration backfills existing
   rows from the products table.

verify + build green.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 17:37:14 +00:00
GandClaude Fable 5 300fe1cdc2 feat(groomers): grooming as a first-class professional vertical (#27)
Groomer joins vet and sitter everywhere a professional exists:
- user_role enum + groomer_profiles (salon, services, from-price) + migration
- /api/groomers browse + /api/groomers/me CRUD; role plumbed through
  registration (?role=groomer), become-a-pro, availability, bookings,
  conflict guard, admin verification, dashboards, sidebar
- Find a Pro gains a Groomers tab; booking modal books grooming as a
  one-hour session with the salon's from-price in the header
- Public pro profile renders groomers (salon, services, starting price)
- Resident groomer Nadia Roth / Salon Pfotenschick seeds via the daily
  cron with a completed booking + 5-star review, so the tab ships alive
- 6 grooming services in the professionals SSOT; role badge tokens in
  globals.css; ~25 strings x 9 locales

Verified end-to-end locally: register groomer -> profile -> visible in
browse -> booked 201 -> overlap 409. verify + build green.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 15:36:56 +00:00
GandClaude Fable 5 d2fcae9824 feat(shop): branded category art — no product ever renders as a placeholder box (#24)
New ProductArt component: uploaded photo when present, otherwise a per-category
line illustration in the brand palette (CSS-var driven, re-themes with
globals.css). Wired into every product surface: portal shop grid + cart drawer,
public shop grid + product detail, buyer/seller/admin order items, seller
product list. Order APIs now expose productCategory for the fallback.

Also: public shop hero title was invisible — .ed-title is platinum-on-dark
marketing typography and PR #22 placed it on the light cream hero; now matches
the adopt page's ink title (surfaces stay unmixed per AGENTS.md).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 12:27:10 +00:00
g-butandClaude Opus 4.7 11d31f7a01 feat(professionals): email notification on verification status change
When an admin verifies or unverifies a professional, the professional
now receives a localized email in their chosen language.

- lib/email/i18n.ts: adds professionalVerification.{verified,unverified}
  strings in all 9 locales (en de fr es ja zh ko tr ar) with Arabic RTL.
- lib/email/templates.ts: professionalVerified() + professionalUnverified()
  template functions using getEmailStrings/t interpolation.
- app/api/admin/professionals/[userId]/route.ts: user select now fetches
  name/email/locale; notifyProfessional() helper sends fire-and-forget
  email after each successful isVerified toggle.
- Tests: 3 new assertions — verified vet gets zh-locale email, unverified
  sitter gets en fallback, null-email user skips send silently.
  i18n namespace coverage test updated to include professionalVerification.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 10:16:59 +02:00
g-butandClaude Opus 4.7 a5941be818 test: cover three recently-shipped routes that lacked tests
Backfilled tests for endpoints added during the marketplace + i18n
work where rapid iteration outpaced test coverage:

- PATCH /api/account/locale: auth gate, missing-locale 400, invalid-
  locale 400, valid-locale success, parametric coverage of every
  locale in routing.locales (so a new locale added to routing won't
  silently break this endpoint).
- GET /api/orders/seller: auth gate, empty-state, multi-order grouping
  with per-seller subtotal computation, and the load-bearing assertion
  that sellerSubtotalCents covers ONLY the seller's items even when
  the buyer's order spans other sellers.
- GET /api/admin/products: admin gate, empty state, LEFT JOIN payload
  shape (platform product → null seller fields; user-listed product →
  populated sellerName/sellerEmail).

12 new tests, suite at 426 pass · 0 fail. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 09:15:37 +02:00
g-butandClaude Opus 4.7 bcb561b250 feat(admin): show fulfillment owner on each order item
GET /api/admin/orders now LEFT JOINs users (aliased as "sellers")
on products.sellerId, returning sellerId/sellerName/sellerEmail
per item. Admin orders panel shows either "Fulfilled by Petvity"
(verified badge) or the seller's name + clickable mailto.

Without this, admins had no way to know which items they should
ship vs which a seller is responsible for — a real fulfillment-
correctness gap once user-listed products entered the marketplace.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 16:57:19 +02:00
g-butandClaude Opus 4.7 6233f84dc1 feat(marketplace): let any user list products via /portal/my-products
- Schema: products.sellerId FK to users (null = platform product) + index
- API: GET ?mine=true scoped to seller; POST defaults sellerId=self,
  admin-only ?platform=true creates sellerId=null; PATCH/DELETE allow
  owner OR admin
- New /api/admin/products returns full list with seller name/email join
- Admin products page now POSTs to /api/products?platform=true
- Portal: /portal/my-products with list, form modal, hide/show toggle,
  soft-delete; sidebar entry under Orders
- i18n: myProducts key in all 9 locales (EN DE FR ES JA ZH KO TR AR)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 15:55:14 +02:00
g-butandClaude Sonnet 4.6 0910dde768 chore(lint): resolve all ESLint errors and warnings — lint now clean
- eslint.config.mjs: add test-file override (disable no-explicit-any,
  allow _-prefixed unused vars) so `db as any` mocks don't block lint
- Fix 2 impure-function errors in public pet page (Date.now → now.getTime)
- Remove stale react-hooks/purity disable directive in health page
- Remove 9 unused imports across route + page files
- Add eslint-disable-next-line comments on intentional <img> tags
  (product/listing/avatar images from dynamic external URLs)
- Replace `_omit` destructuring alias with conventional `_` in test files
- Remove unused makeGetRequest helper in pets route test

Lint: 0 errors · 0 warnings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 12:52:10 +02:00
g-butandClaude Sonnet 4.6 b3d60d71a7 test(api): add final read-only route tests — 329 tests total
Cover admin/adoptions GET (sql subquery aggregates), admin/orders GET
(two-pass join + item grouping), products GET/POST, products/[productId]
PATCH/DELETE (soft-delete), vets + sitters GET (city filter + review
aggregates), and public/pets/[handle] GET (private field exclusion).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 22:30:52 +02:00
g-butandClaude Sonnet 4.6 2bfb48cd4f test(api): add integration tests for admin users and professionals routes
18 new tests: admin/users GET (401, empty list, isVerified=null for pet_owner,
isVerified from vetProfiles); admin/users/[userId] PATCH (401, invalid role,
self-demotion guard, last-admin guard, promote, 404); admin/professionals/[userId]
PATCH (401, 400 non-pro, 404 no profile, 200 verify vet/sitter, 404 no profile).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 22:12:18 +02:00
g-butandClaude Sonnet 4.6 c62c28cdbc feat(admin): add adoption listings management panel
- GET /api/admin/adoptions — all listings with pet, owner, application
  counts and pending-application count via subquery
- /admin/adoptions page — summary strip (total/available/pending/adopted),
  filter pills, expandable rows with pet avatar, owner info, location,
  fee, application counts
- Admin can change any listing status (available / on_hold / adopted /
  withdrawn) via PATCH /api/adoptions/[listingId] (already admin-allowed)
- Adoptions link added to admin sidebar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 10:17:01 +02:00
g-butandClaude Sonnet 4.6 e5ecc79587 feat(admin): add orders management panel with fulfillment workflow
- GET /api/admin/orders — all orders with customer info + line items
- /admin/orders page: summary stats (total, revenue, pending, in-transit),
  status filter pills, expandable order rows with customer detail + items
- Admin can advance orders through: pending → confirmed → shipped → delivered,
  or cancel at any pre-delivery stage
- Orders link added to admin sidebar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 09:17:58 +02:00
g-butandClaude Sonnet 4.6 2fdae4ddfb feat(admin): add professional verification — isVerified toggle in admin panel
- Add /api/admin/professionals/[userId] PATCH endpoint (admin-only, sets isVerified)
- Update /api/admin/users GET to include isVerified status for vet/sitter users
- Admin users table: Verified column with Verify/revoke toggle buttons
- VerifyCell component: handles no-profile, unverified, and verified states
- Stats card: replace Admins count with Verified Profiles count
- Use inArray() instead of or(...map()) for professional ID filtering

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 15:19:42 +02:00
g-butandClaude Sonnet 4.6 da93c12230 feat(admin): add role management — promote users to vet/sitter/admin
- New PATCH /api/admin/users/[userId] endpoint (admin-only) with guards
  against self-demotion and removing the last admin
- Admin users page: inline role dropdown per row, optimistic update,
  "Saving…" indicator; adds Veterinarians stat card

Unblocks Phase 2: admins can now promote users to veterinarian/pet_sitter
so they can create professional profiles and accept bookings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 14:14:55 +02:00
g-butandClaude Sonnet 4.6 cfadd2ba2e feat(admin): add admin panel users page + health chart polish
Admin panel:
- app/(admin)/admin/layout.tsx: dark sidebar with teal logo, user chip, back-to-portal link
- app/(admin)/admin/users/page.tsx: users table with stats (total, pets, admins), role badges
- app/api/admin/users/route.ts: GET all users with pet count (requireAdmin guard)

Health page polish:
- Replace bg-green-50/bg-red-50 raw classes with design tokens (--green-bg/--danger-bg)
- Swap 📊 emoji empty state for Lucide BarChart3 icon in teal box
- Replace ← text arrow with ChevronLeft icon

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 15:12:44 +02:00