fix: normalize audit log response to ensure entries are always an array and total is a number, improving data handling in OrganizationSettings
This commit is contained in:
@@ -55,6 +55,7 @@ async function auditFetch<T>(endpoint: string, options: RequestInit = {}): Promi
|
||||
|
||||
/**
|
||||
* Fetches paginated audit log entries for the current org (org from JWT; admin-only on backend).
|
||||
* Normalizes response so entries is always an array (backend may return null when empty).
|
||||
*/
|
||||
export async function getAuditLog(params: GetAuditLogParams = {}): Promise<GetAuditLogResponse> {
|
||||
const search = new URLSearchParams()
|
||||
@@ -65,5 +66,9 @@ export async function getAuditLog(params: GetAuditLogParams = {}): Promise<GetAu
|
||||
if (params.end_date) search.set('end_date', params.end_date)
|
||||
const qs = search.toString()
|
||||
const url = qs ? `/api/audit?${qs}` : '/api/audit'
|
||||
return await auditFetch<GetAuditLogResponse>(url, { method: 'GET' })
|
||||
const data = await auditFetch<GetAuditLogResponse>(url, { method: 'GET' })
|
||||
return {
|
||||
entries: Array.isArray(data?.entries) ? data.entries : [],
|
||||
total: typeof data?.total === 'number' ? data.total : 0,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user