admin roadmap csv export, adminactionlog, global search

This commit is contained in:
2026-05-18 20:09:22 +07:00
parent 244a6da9bb
commit ea63f56e97
25 changed files with 1330 additions and 158 deletions
+50
View File
@@ -0,0 +1,50 @@
import { Prisma } from "@/app/generated/prisma/client";
import { prisma } from "@/lib/prisma";
/**
* Helper untuk catat aksi admin ke `AdminActionLog`. Append-only, idempotent
* terhadap kegagalan: kalau insert log gagal, jangan blok action — cuma
* console.error supaya monitoring bisa pick up.
*
* Pemakaian (di akhir admin action, setelah success):
* ```ts
* await auditLog.record({
* admin: { id: session.user.id, email: session.user.email },
* action: "REFUND_APPROVE",
* entityType: "Refund",
* entityId: refundId,
* payload: { adminNote },
* });
* ```
*/
export const auditLog = {
async record(input: {
admin: { id: string; email: string };
action: string;
entityType: string;
entityId: string;
payload?: Record<string, unknown>;
}): Promise<void> {
try {
await prisma.adminActionLog.create({
data: {
adminId: input.admin.id,
adminEmail: input.admin.email,
action: input.action,
entityType: input.entityType,
entityId: input.entityId,
payload: input.payload
? (input.payload as Prisma.InputJsonValue)
: Prisma.JsonNull,
},
});
} catch (err) {
console.error("[audit-log] gagal record action", {
action: input.action,
entityType: input.entityType,
entityId: input.entityId,
err,
});
}
},
};