From 26b0cf12e375c928a7c81254bde7d678ef5ab98b Mon Sep 17 00:00:00 2001 From: Khafid Prayoga Date: Thu, 11 Sep 2025 13:28:07 +0700 Subject: [PATCH] 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. --- app/components/content/division/list.vue | 14 +--- app/components/content/equipment/list.vue | 27 ++----- app/components/content/installation/list.vue | 26 ++----- app/components/content/specialist/list.vue | 26 ++----- app/components/content/tools/list.vue | 14 +--- app/components/content/unit/list.vue | 14 +--- app/composables/usePaginatedList.ts | 74 ++++++++++++-------- 7 files changed, 70 insertions(+), 125 deletions(-) diff --git a/app/components/content/division/list.vue b/app/components/content/division/list.vue index f4bf78e6..f6a3efc7 100644 --- a/app/components/content/division/list.vue +++ b/app/components/content/division/list.vue @@ -18,19 +18,9 @@ const recId = ref(0) const recAction = ref('') const recItem = ref(null) -// Fungsi untuk fetch data division async function fetchDivisionData(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 diff --git a/app/components/content/equipment/list.vue b/app/components/content/equipment/list.vue index 61d2a0b0..4c82ed92 100644 --- a/app/components/content/equipment/list.vue +++ b/app/components/content/equipment/list.vue @@ -24,19 +24,10 @@ const items = [ { value: 'item-3', label: 'Item 3' }, ] -// Fungsi untuk fetch data division +// Fungsi untuk fetch data equipment async function fetchEquipmentData(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/equipment?${urlParams.toString()}`) + const endpoint = transform('/api/v1/equipment', params) + return await xfetch(endpoint) } // Menggunakan composable untuk pagination @@ -188,17 +179,13 @@ const handleCancelConfirmation = () => { - + - +