57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { db } from "@/lib/db";
|
|
import { getCurrentSession } from "@/lib/session";
|
|
import { activityLog } from "./schema";
|
|
|
|
export async function logActivity(input: {
|
|
entityType: string;
|
|
entityId: string;
|
|
action: string;
|
|
payload?: Record<string, unknown>;
|
|
}): Promise<void> {
|
|
const { user, household } = await getCurrentSession();
|
|
await db.insert(activityLog).values({
|
|
householdId: household.id,
|
|
entityType: input.entityType,
|
|
entityId: input.entityId,
|
|
actorId: user.id,
|
|
action: input.action,
|
|
payload: input.payload ?? null,
|
|
});
|
|
}
|
|
|
|
export async function logShareActivity(input: {
|
|
householdId: string;
|
|
entityType: string;
|
|
entityId: string;
|
|
action: string;
|
|
payload?: Record<string, unknown>;
|
|
}): Promise<void> {
|
|
await db.insert(activityLog).values({
|
|
householdId: input.householdId,
|
|
entityType: input.entityType,
|
|
entityId: input.entityId,
|
|
actorId: null,
|
|
action: input.action,
|
|
payload: input.payload ?? null,
|
|
});
|
|
}
|
|
|
|
export async function logActivityForScope(
|
|
scope: { householdId: string; userId: string | null },
|
|
input: {
|
|
entityType: string;
|
|
entityId: string;
|
|
action: string;
|
|
payload?: Record<string, unknown>;
|
|
},
|
|
): Promise<void> {
|
|
await db.insert(activityLog).values({
|
|
householdId: scope.householdId,
|
|
entityType: input.entityType,
|
|
entityId: input.entityId,
|
|
actorId: scope.userId,
|
|
action: input.action,
|
|
payload: input.payload ?? null,
|
|
});
|
|
}
|