mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 22:18:12 +00:00
feat: implement audit logs
This commit is contained in:
@@ -163,6 +163,11 @@ import {
|
||||
type SaveLocomotivePayload,
|
||||
} from "./locomotives.service";
|
||||
import { overviewService } from "./overview.service";
|
||||
import {
|
||||
auditService,
|
||||
type AuditLogListFilter,
|
||||
type PaginatedAuditLogs,
|
||||
} from "./audit.service";
|
||||
import { reportsService } from "./reports.service";
|
||||
import type { ReportQueryInput, ReportResult } from "@/types/reports";
|
||||
import {
|
||||
@@ -2136,6 +2141,15 @@ export const api = {
|
||||
),
|
||||
},
|
||||
|
||||
audit: {
|
||||
list: endpoint<{ filter?: AuditLogListFilter }, PaginatedAuditLogs>(
|
||||
"audit",
|
||||
"list",
|
||||
({ filter }) => auditService.list(filter),
|
||||
({ filter }) => ["audit", "list", filter ?? {}],
|
||||
),
|
||||
},
|
||||
|
||||
signatures: {
|
||||
mySignature: endpoint<void, SavedSignature | null>(
|
||||
"me",
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { api as client } from "../auth/http";
|
||||
import { unwrap } from "@/utils/endpoint";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
|
||||
const A = URL_CONSTANTS.AUDIT;
|
||||
|
||||
// Shape from @tria-plc/auditlog's AuditLogCommandController — see
|
||||
// local-packages/FRONTEND_GUIDE.md.
|
||||
export type AuditQueryMethod =
|
||||
| "INSERT"
|
||||
| "UPDATE"
|
||||
| "DELETE"
|
||||
| "INSERT_CHILD"
|
||||
| "DELETE_CHILD";
|
||||
|
||||
export interface AuditFieldChange {
|
||||
field: string;
|
||||
from: unknown;
|
||||
to: unknown;
|
||||
}
|
||||
|
||||
export interface AuditUser {
|
||||
id?: string;
|
||||
name?: string;
|
||||
organizationId?: string;
|
||||
organizationName?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface AuditLogRow {
|
||||
id?: string;
|
||||
createdAt: string;
|
||||
deletedAt?: string | null;
|
||||
entityName: string;
|
||||
queryMethod: AuditQueryMethod;
|
||||
changes?: AuditFieldChange[] | null;
|
||||
payload?: { name?: string; title?: string; id?: string } | null;
|
||||
auditLog?: { id?: string; user?: AuditUser | null };
|
||||
}
|
||||
|
||||
export interface AuditLogListFilter {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
}
|
||||
|
||||
export interface PaginatedAuditLogs {
|
||||
items: AuditLogRow[];
|
||||
count: number;
|
||||
}
|
||||
|
||||
export const auditService = {
|
||||
list: async (filter?: AuditLogListFilter): Promise<PaginatedAuditLogs> => {
|
||||
const params: Record<string, number | undefined> = {
|
||||
skip: filter?.skip,
|
||||
take: filter?.take,
|
||||
};
|
||||
const response = await client.get<PaginatedAuditLogs>(A.LOGS, { params });
|
||||
const data = unwrap(response.data) as PaginatedAuditLogs;
|
||||
return { items: data.items ?? [], count: data.count ?? 0 };
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user