Files
growqr-backend/src/events/route-to-user-actor.ts
2026-06-04 16:12:32 +05:30

16 lines
710 B
TypeScript

import { createClient, type Client } from "rivetkit/client";
import { config } from "../config.js";
import type { Registry } from "../actors/registry.js";
import type { GrowEventRow } from "../db/schema.js";
let _client: Client<Registry> | null = null;
function getClient(): Client<Registry> {
return (_client ??= createClient<Registry>(config.rivetClientEndpoint));
}
export async function routeGrowEventToUserActor(event: Pick<GrowEventRow, "id" | "userId">) {
if (!event.userId) return { routed: false, reason: "unresolved_user" } as const;
await getClient().userEventActor.getOrCreate([event.userId]).enqueueEvent({ userId: event.userId, eventId: event.id });
return { routed: true } as const;
}