feat(core) : add audit log consultation tab in admin gated by permission
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import type { HydraCollection } from '~/utils/api'
|
||||
import { extractHydraMembers } from '~/utils/api'
|
||||
|
||||
export type AuditLogAction = 'create' | 'update' | 'delete'
|
||||
|
||||
export type AuditLogItem = {
|
||||
id: string
|
||||
'@id'?: string
|
||||
entityType: string
|
||||
entityId: string
|
||||
action: AuditLogAction
|
||||
changes: Record<string, unknown>
|
||||
performedBy: string
|
||||
performedAt: string
|
||||
ipAddress: string | null
|
||||
requestId: string | null
|
||||
}
|
||||
|
||||
export type AuditLogQuery = {
|
||||
page?: number
|
||||
entityType?: string
|
||||
action?: AuditLogAction
|
||||
}
|
||||
|
||||
export type AuditLogPage = {
|
||||
items: AuditLogItem[]
|
||||
totalItems: number
|
||||
}
|
||||
|
||||
export type AuditLogEntityType = {
|
||||
'@id'?: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export function useAuditLogService() {
|
||||
const api = useApi()
|
||||
|
||||
async function list(params: AuditLogQuery = {}): Promise<AuditLogPage> {
|
||||
const query: Record<string, unknown> = {}
|
||||
if (params.page !== undefined) {
|
||||
query.page = params.page
|
||||
}
|
||||
if (params.entityType) {
|
||||
query.entity_type = params.entityType
|
||||
}
|
||||
if (params.action) {
|
||||
query.action = params.action
|
||||
}
|
||||
|
||||
const data = await api.get<HydraCollection<AuditLogItem>>('/audit-logs', query)
|
||||
return {
|
||||
items: extractHydraMembers(data),
|
||||
totalItems: data['hydra:totalItems'] ?? data['totalItems'] ?? 0,
|
||||
}
|
||||
}
|
||||
|
||||
async function entityTypes(): Promise<string[]> {
|
||||
const data = await api.get<HydraCollection<AuditLogEntityType>>('/audit-log-entity-types')
|
||||
return extractHydraMembers(data).map((entry) => entry.value)
|
||||
}
|
||||
|
||||
return { list, entityTypes }
|
||||
}
|
||||
Reference in New Issue
Block a user