USRSE / USRSE/usrse.github.io

refactor(api): extract shared artifact-admin helpers (list query, scope defaults, slugify)

Open
#2,002 0 comments 0 reactions 0 assignees View on GitHub

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) to packages/api/src/lib/slug.ts (currently duplicated in admin/events/index.ts and eventsSubmit.ts)
  • Refactor admin/events/index.ts, admin/events/byId.ts, admin/announcements/index.ts, admin/announcements/byId.ts, and eventsSubmit.ts to 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.