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:
Usman Baig
2026-02-05 12:30:01 +01:00
parent 54578d00ca
commit bcb221eb41
2 changed files with 10 additions and 5 deletions

View File

@@ -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,
}
}