Skip to content

refactor: support PATCH and dynamic paths in useApiMutation - #302

Merged
plz12345 merged 1 commit into
Whisparr:eros-developfrom
Mothball7205:request-helper-refactor
Jun 14, 2026
Merged

refactor: support PATCH and dynamic paths in useApiMutation#302
plz12345 merged 1 commit into
Whisparr:eros-developfrom
Mothball7205:request-helper-refactor

Conversation

@Mothball7205

@Mothball7205 Mothball7205 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Database Migration

NO

Description

add PATCH to the allowed methods and allow path to be a function of the mutation data, so dynamic routes like /history/failed/{id} can go through the standard client.
backwards compatible, string paths are unchanged

Fixes Unrelated Issues

  • mutationOptions leaked into fetchJson — the old spread { ...options } included mutationOptions in requestOptions, which then ended up in ...otherOptions and was passed directly to fetchJson. The new explicit destructure correctly excludes it.
  • queryParams leaked the same way — same issue, same fix.

Todos

  • Tests

@Mothball7205
Mothball7205 marked this pull request as draft June 11, 2026 10:48
@Mothball7205
Mothball7205 force-pushed the request-helper-refactor branch from b32cf4e to be20897 Compare June 11, 2026 11:22
@Mothball7205
Mothball7205 marked this pull request as ready for review June 11, 2026 11:26
@plz12345

Copy link
Copy Markdown
Contributor

This is already standardized in useApiQuery.ts , unless I'm missing your point. Your code should be reusing that client unless not possible, and if not, let's figure out why.

@Mothball7205

Copy link
Copy Markdown
Contributor Author

This is already standardized in useApiQuery.ts , unless I'm missing your point. Your code should be reusing that client unless not possible, and if not, let's figure out why.

@plz12345 thanks. you're right. i looked at it and i could remove the apiRequest.ts and use useApiMutation.ts/useApiQuery.ts.

the only problem is that useApiMutation binds the path once at the hook creation, which means when we have dynamic paths like /history/failed/${historyId} its basically not possible to use it.

i could add a function path path: string | ((data: TData) => string) to the useApiMutation to allow variables in the path at mutation time. i think that should be pretty clean

const markFailed = useApiMutation<void, number>({
  method: 'POST',
  path: (historyId) => `/history/failed/${historyId}`,
  mutationOptions: {...

@Mothball7205 Mothball7205 changed the title refactor: centralize authenticated API requests refactor: migrate API calls onto useApiMutation and useApiQuery Jun 12, 2026
@plz12345

Copy link
Copy Markdown
Contributor

Can we...not refactor half the front end just to do the one API call you had on the other PR? At most, stick to object boundaries, (movie/scene, performer, studio), and don't start with the heaviest ones. It's too much risk without any unit testing on the changes (yes, I realize that's pot/kettle/black based on existing source).

@Mothball7205

Copy link
Copy Markdown
Contributor Author

yeah you're right... for some reason i was thinking "this is just one fix, it makes sense to be this size."

i will keep the PRs smaller. i know it can be tiring reviewing PRs and i dont wanna add to that.

for this one would just the useApiMutation change be ok? PATCH support + allowing dynamic paths (so stuff like /history/failed/{id} can use it). that would make the existing // TODO: Move to useApiMutation parts doable, but i'd leave those for now

@plz12345

Copy link
Copy Markdown
Contributor

Yeah, if it's a new function, no real risk, and other stuff can consume it, like your other PR, History (later) etc.

@Mothball7205
Mothball7205 force-pushed the request-helper-refactor branch from deb4622 to fcafbd0 Compare June 13, 2026 11:56
@Mothball7205 Mothball7205 changed the title refactor: migrate API calls onto useApiMutation and useApiQuery refactor: support PATCH and dynamic paths in useApiMutation Jun 13, 2026
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@plz12345
plz12345 merged commit 2817723 into Whisparr:eros-develop Jun 14, 2026
34 checks passed
@Mothball7205
Mothball7205 deleted the request-helper-refactor branch June 14, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants