DUP-TS-5: URLSearchParams builder pattern repeated 7 times in api.ts #50

Closed
opened 2026-05-27 16:57:47 +02:00 by dries · 0 comments
Owner

Summary

Seven API methods in frontend/src/lib/api.ts repeat the same ~6-line pattern for building query strings: metrics, sessions, sessionsNotify, activity, models, hourly, hourlyTokens.

Duplicated pattern

const q = new URLSearchParams();
if (params?.X) q.set('X', String(params.X));
// ... more params ...
const qs = q.toString();
return fetchJSON<T>(`/api/route${qs ? '?' + qs : ''}`, signal);

Fix

Extract a helper buildQueryString(params: Record<string, unknown>): string that filters nullish values and handles the ? + prefix. All seven callers become a single fetchJSON call.

Effort

Trivial.

## Summary Seven API methods in `frontend/src/lib/api.ts` repeat the same ~6-line pattern for building query strings: `metrics`, `sessions`, `sessionsNotify`, `activity`, `models`, `hourly`, `hourlyTokens`. ## Duplicated pattern ```ts const q = new URLSearchParams(); if (params?.X) q.set('X', String(params.X)); // ... more params ... const qs = q.toString(); return fetchJSON<T>(`/api/route${qs ? '?' + qs : ''}`, signal); ``` ## Fix Extract a helper `buildQueryString(params: Record<string, unknown>): string` that filters nullish values and handles the `? +` prefix. All seven callers become a single `fetchJSON` call. ## Effort Trivial.
dries closed this issue 2026-07-11 11:23:18 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#50
No description provided.