Skip to content

Commit

Permalink
feat: audit logs
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Oct 21, 2023
1 parent d60868a commit d827993
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class CADSettingsController {
@QueryParams("skip", Number) skip = 0,
@QueryParams("query", String) query?: string,
@QueryParams("type", String) type?: string,
@QueryParams("sorting") sorting = "",
): Promise<any> {
const OR: Prisma.Enumerable<Prisma.AuditLogWhereInput> = [];
const _typeWhere: Prisma.Enumerable<Prisma.AuditLogWhereInput> | undefined =
Expand All @@ -112,12 +113,13 @@ export class CADSettingsController {

const where = { OR: OR.length > 0 ? OR : undefined };

const orderBy = getPrismaModelOrderBy(sorting);
const [totalCount, auditLogs] = await prisma.$transaction([
prisma.auditLog.count({ where }),
prisma.auditLog.findMany({
take: 35,
skip,
orderBy: { createdAt: "desc" },
orderBy: sorting ? orderBy : { createdAt: "desc" },
include: { executor: { select: userProperties } },
where,
}),
Expand Down
9 changes: 8 additions & 1 deletion apps/client/src/pages/admin/manage/audit-logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default function ManageAuditLogs({ data }: Props) {

const asyncTable = useAsyncTable({
search,
sortingSchema: {
executor: "executor.username",
createdAt: "createdAt",
},
fetchOptions: {
path: "/admin/manage/cad-settings/audit-logs",
onResponse: (data: GetAuditLogsData) => ({
Expand All @@ -49,7 +53,10 @@ export default function ManageAuditLogs({ data }: Props) {
initialData: data.logs,
});

const tableState = useTableState({ pagination: asyncTable.pagination });
const tableState = useTableState({
sorting: asyncTable.sorting,
pagination: asyncTable.pagination,
});

return (
<AdminLayout
Expand Down

0 comments on commit d827993

Please sign in to comment.