wutzcalc/server
Repository files (latest commit first)
Filename Latest commit message Latest commit date
iris d6e9979439 admin: close six 500-instead-of-4xx gaps on drink/bar CRUD endpoints
Six defensive-check gaps in server/src/routes/admin.ts, all the same
theme (missing the same check a sibling endpoint already has):

1. PATCH /admin/api/drinks/:id with a taken name 500'd instead of 409 —
   the bar-rename equivalent (and drink POST) already catch the UNIQUE
   constraint, this endpoint didn't.
2. PATCH /admin/api/bars/:id with a nonexistent drink_id 500'd instead of
   400 — drink_ids was only checked for integer-ness, not existence, so a
   bogus id hit an uncaught FK-constraint error. Now validated against the
   drinks table up front (rollback was already correct, this only fixes
   the status code).
3. PATCH /admin/api/bars/:id on a nonexistent bar silently returned
   200 {ok:true} — the drinks-PATCH equivalent checks info.changes === 0
   and 404s, this endpoint checked nothing. Now 404s up front.
4. Non-string name in any of the four drink/bar POST/PATCH endpoints
   500'd (object/numeric name hit an uncaught TypeError calling .trim()
   on a non-string, or an uncaught SQLite type error). All four now
   typeof-guard before use.
5. Drink names weren't trimmed or checked for emptiness, unlike bars —
   an empty/whitespace name showed as a blank tablet tile, and a
   trailing-space variant of an existing name bypassed the UNIQUE index
   and split that drink's stats across two rows. Drink POST/PATCH now
   trim + reject blank, matching bars.

Verified all six against a scratch DB with the real server running
end-to-end (login, each failure case, plus a same-request-shape sanity
check that valid updates still succeed). tsc --noEmit and the server
build both clean.
2026-07-31 11:07:49 +02:00
..
migrations snapshot the Pfand rate used for returns, like every other money value already is 2026-07-29 20:26:52 +02:00
src admin: close six 500-instead-of-4xx gaps on drink/bar CRUD endpoints 2026-07-31 11:07:49 +02:00
package.json scaffold festival drink tracker (pnpm workspace, Fastify + SQLite, Preact tablet UI, admin) 2026-05-19 18:12:01 +02:00
tsconfig.json scaffold festival drink tracker (pnpm workspace, Fastify + SQLite, Preact tablet UI, admin) 2026-05-19 18:12:01 +02:00