♻️ Transformed API keys

This commit is contained in:
2025-09-19 01:26:21 +08:00
parent 60e8b1dcfb
commit 48a9a97e18
9 changed files with 171 additions and 95 deletions

View File

@@ -1,10 +1,28 @@
// Solar Network aka the api client
import { keysToCamel, keysToSnake } from '~/utils/transformKeys'
export const useSolarNetwork = () => {
const apiBase = useSolarNetworkUrl();
return $fetch.create({ baseURL: apiBase, credentials: 'include' })
return $fetch.create({
baseURL: apiBase,
credentials: 'include',
// Transform response keys from snake_case to camelCase
onResponse: ({ response }) => {
if (response._data) {
response._data = keysToCamel(response._data)
}
},
// Transform request data from camelCase to snake_case
onRequest: ({ options }) => {
if (options.body && typeof options.body === 'object') {
options.body = keysToSnake(options.body)
}
}
})
}
export const useSolarNetworkUrl = () => {
const config = useRuntimeConfig()
return config.public.apiBase
}
}