refactor(api): extract shared artifact-admin helpers (list query, scope defaults, slugify)
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 33
- Forks
- 104
- Avg merge
- 12h 3m
- Merged PRs (30d)
- 10
Description
Summary
The admin routes for events and announcements are 80%+ identical: zod validation schemas, list-query where builder, scope-by-author-class defaulting, pagination shape, audit-row writing on PATCH. Plans 4 (forms) and 5 (broadcast) will add more parallel surfaces; extract before that hardens.
Requirements
- Extract
buildArtifactListWhere(table, query, allowedStatuses, allowedScopes)to a shared module - Extract
inferDefaultScope(actor)helper - Extract
slugify(name)topackages/api/src/lib/slug.ts(currently duplicated inadmin/events/index.tsandeventsSubmit.ts) - Refactor
admin/events/index.ts,admin/events/byId.ts,admin/announcements/index.ts,admin/announcements/byId.ts, andeventsSubmit.tsto use the shared helpers - All existing tests still pass
Context
Flagged in both the Plan 2 and Plan 3 final reviews. Parallel artifact types are intentionally separated at the table level, but the route-construction code wants to be shared.
Implementation Notes
Keep the per-artifact-type sub-app structure (one folder per artifact under routes/admin/) — only the helpers move out. Don't introduce a polymorphic router; that fights Drizzle's type narrowing.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the duplicated logic in admin/events/index.ts, admin/events/byId.ts, admin/announcements/index.ts, admin/announcements/byId.ts, and eventsSubmit.ts. Extract the three named helpers into shared modules while preserving the per-artifact route structure, then run the existing test suite; done means all listed routes use the helpers and tests pass.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend-api-design
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100