import { DateUtils } from '@repo/utils'; export const EMPTY_AUDIT_DISPLAY = '-'; const AUDIT_TIMESTAMP_FORMAT = 'DD-MM-YYYY, HH:mm'; export function resolveAuditValue( row: Record | null | undefined, camelKey: string, snakeKey: string, ): unknown { if (!row) return undefined; const camelValue = row[camelKey]; if (camelValue !== undefined && camelValue !== null) return camelValue; return row[snakeKey]; } export function formatAuditActor(value: unknown): string { if (value === undefined || value === null || value === '') return EMPTY_AUDIT_DISPLAY; if (typeof value === 'string') return value; if (typeof value === 'object') { const actor = value as { username?: unknown; name?: unknown; id?: unknown }; const label = actor.username ?? actor.name ?? actor.id; if (label === undefined || label === null || label === '') return EMPTY_AUDIT_DISPLAY; return String(label); } return String(value); } export function formatAuditTimestamp(value: unknown): string { if (value === undefined || value === null || value === '') return EMPTY_AUDIT_DISPLAY; return new DateUtils(Number(value)).format(AUDIT_TIMESTAMP_FORMAT); }