refactor(api): consolidate query param transformation into utility function

Move URL parameter construction logic from multiple list components to a shared transform function in usePaginatedList. This improves code reuse and maintainability while keeping the same functionality.

Standardize query parameter names to match backend expectations ('page-number' and 'page-size' instead of 'page' and 'pageSize'). Update related schema and default params accordingly.
This commit is contained in:
Khafid Prayoga
2025-09-11 13:28:07 +07:00
parent 140bfa0420
commit 26b0cf12e3
7 changed files with 70 additions and 125 deletions
+2 -12
View File
@@ -18,19 +18,9 @@ const recId = ref<number>(0)
const recAction = ref<string>('')
const recItem = ref<any>(null)
// Fungsi untuk fetch data unit
async function fetchUnitData(params: any) {
// Prepare query parameters for pagination and search
const urlParams = new URLSearchParams({
'page-number': params.page.toString(),
'page-size': params.pageSize.toString(),
})
if (params.q) {
urlParams.append('search', params.q)
}
return await xfetch(`/api/v1/patient?${urlParams.toString()}`)
const endpoint = transform('/api/v1/patient', params)
return await xfetch(endpoint)
}
// Menggunakan composable untuk pagination