mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
fix: retain import actor attribution
Persist record and actor identities through job completion.\nWrite one bounded transactional completion audit per job.
This commit is contained in:
1 parent
adb932052c
commit
620817b10b
19 files changed
+211
-63
No files matched your search
+10
-2
@@ -49,16 +49,24 @@ export async function auditLog(
|
||||
action: string,
|
||||
opts: {
|
||||
userId?: string | null;
|
||||
/** Explicit worker attribution when no request context remains. */
|
||||
actorUserId?: string | null;
|
||||
/** Use the active transaction when the audit must commit atomically. */
|
||||
client?: Pick<typeof prisma, "auditLog">;
|
||||
details?: Record<string, unknown>;
|
||||
ipAddress?: string | null;
|
||||
} = {},
|
||||
) {
|
||||
const userId = opts.userId ?? null;
|
||||
const entry = await prisma.auditLog.create({
|
||||
const client = opts.client ?? prisma;
|
||||
const entry = await client.auditLog.create({
|
||||
data: {
|
||||
action,
|
||||
userId,
|
||||
actorUserId: actingActorFor(userId),
|
||||
actorUserId:
|
||||
opts.actorUserId === undefined
|
||||
? actingActorFor(userId)
|
||||
: opts.actorUserId,
|
||||
details: opts.details ? JSON.stringify(opts.details) : null,
|
||||
ipAddress: opts.ipAddress ?? null,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user