2026-01-25 22:47:53 +00:00
|
|
|
import { type } from "arktype"
|
|
|
|
|
|
2026-02-18 00:41:20 +00:00
|
|
|
import type { UserSessionManager } from "../session/index.ts"
|
2026-01-25 22:47:53 +00:00
|
|
|
import type { TRPC } from "../trpc/router.ts"
|
2026-02-13 19:16:33 +00:00
|
|
|
|
2026-01-25 22:47:53 +00:00
|
|
|
const locationInput = type({
|
|
|
|
|
lat: "number",
|
|
|
|
|
lng: "number",
|
|
|
|
|
accuracy: "number",
|
|
|
|
|
timestamp: "Date",
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-13 19:16:33 +00:00
|
|
|
export function createLocationRouter(
|
|
|
|
|
t: TRPC,
|
2026-02-18 00:41:20 +00:00
|
|
|
{ sessionManager }: { sessionManager: UserSessionManager },
|
2026-02-13 19:16:33 +00:00
|
|
|
) {
|
2026-01-25 22:47:53 +00:00
|
|
|
return t.router({
|
2026-02-18 00:41:20 +00:00
|
|
|
update: t.procedure.input(locationInput).mutation(async ({ input, ctx }) => {
|
|
|
|
|
const session = sessionManager.getOrCreate(ctx.user.id)
|
|
|
|
|
await session.engine.executeAction("aris.location", "update-location", {
|
|
|
|
|
lat: input.lat,
|
|
|
|
|
lng: input.lng,
|
|
|
|
|
accuracy: input.accuracy,
|
|
|
|
|
timestamp: input.timestamp,
|
|
|
|
|
})
|
2026-01-25 22:47:53 +00:00
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
}
|