Introduced Paginated Data, Listing to StandardEntitys
This commit is contained in:
@@ -36,6 +36,83 @@ export const useEntities = (
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
const selectPaginated = async (options: {
|
||||
select?: string
|
||||
filters?: Record<string, any>
|
||||
sort?: { field: string; direction?: 'asc' | 'desc' }[]
|
||||
page?: number
|
||||
limit?: number
|
||||
includeArchived?: boolean
|
||||
noPagination?: boolean,
|
||||
search?: string,
|
||||
searchColumns?: string[],
|
||||
distinctColumns?: string[],
|
||||
}): Promise<{ data: any[]; meta: any }> => {
|
||||
const {
|
||||
select = '*',
|
||||
filters = {},
|
||||
sort = [],
|
||||
page = 1,
|
||||
limit = 25,
|
||||
includeArchived = false,
|
||||
noPagination = false,
|
||||
search,
|
||||
searchColumns = [],
|
||||
distinctColumns = [],
|
||||
} = options
|
||||
|
||||
const queryParams: Record<string, any> = {
|
||||
select,
|
||||
page,
|
||||
limit,
|
||||
noPagination: noPagination ? 'true' : undefined
|
||||
}
|
||||
|
||||
// --- 🔍 Search-Parameter (optional) ---
|
||||
if (search && search.trim().length > 0) {
|
||||
queryParams.search = search.trim()
|
||||
}
|
||||
if (searchColumns.length > 0) queryParams.searchColumns = searchColumns.join(',')
|
||||
if (distinctColumns.length > 0) queryParams.distinctColumns = distinctColumns.join(',')
|
||||
|
||||
|
||||
// --- Sortierung ---
|
||||
if (sort.length > 0) {
|
||||
queryParams.sort = sort
|
||||
.map(s => `${s.field}:${s.direction || 'asc'}`)
|
||||
.join(',')
|
||||
}
|
||||
|
||||
// --- Filter ---
|
||||
for (const [key, value] of Object.entries(filters)) {
|
||||
if (Array.isArray(value)) {
|
||||
queryParams[`filter[${key}]`] = value.join(',')
|
||||
} else {
|
||||
queryParams[`filter[${key}]`] = value
|
||||
}
|
||||
}
|
||||
|
||||
const response = await useNuxtApp().$api(`/api/resource/${relation}/paginated`, {
|
||||
method: 'GET',
|
||||
params: queryParams
|
||||
})
|
||||
|
||||
if (!response) {
|
||||
return { data: [], meta: null }
|
||||
}
|
||||
|
||||
let data = response.data || []
|
||||
const meta = response.queryConfig || {}
|
||||
|
||||
// --- Optional: Archivierte ausblenden ---
|
||||
if (!includeArchived) {
|
||||
data = data.filter((i: any) => !i.archived)
|
||||
}
|
||||
|
||||
return { data, meta }
|
||||
}
|
||||
|
||||
const selectSpecial = async (
|
||||
select: string = "*",
|
||||
sortColumn: string | null = null,
|
||||
@@ -134,7 +211,7 @@ export const useEntities = (
|
||||
|
||||
}
|
||||
|
||||
return {select, create, update, archive, selectSingle, selectSpecial}
|
||||
return {select, create, update, archive, selectSingle, selectSpecial, selectPaginated}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user