mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
Manage per-user WeatherSource instances via FeedSourceProvider, following the same pattern as LocationService. Wire into FeedEngineService so weather data is included in the feed. Co-authored-by: Ona <no-reply@ona.com>
38 lines
890 B
TypeScript
38 lines
890 B
TypeScript
import { TRPCError } from "@trpc/server"
|
|
import { type } from "arktype"
|
|
|
|
import type { TRPC } from "../trpc/router.ts"
|
|
import type { LocationService } from "./service.ts"
|
|
|
|
import { UserNotFoundError } from "../lib/error.ts"
|
|
|
|
const locationInput = type({
|
|
lat: "number",
|
|
lng: "number",
|
|
accuracy: "number",
|
|
timestamp: "Date",
|
|
})
|
|
|
|
export function createLocationRouter(
|
|
t: TRPC,
|
|
{ locationService }: { locationService: LocationService },
|
|
) {
|
|
return t.router({
|
|
update: t.procedure.input(locationInput).mutation(({ input, ctx }) => {
|
|
try {
|
|
locationService.updateUserLocation(ctx.user.id, {
|
|
lat: input.lat,
|
|
lng: input.lng,
|
|
accuracy: input.accuracy,
|
|
timestamp: input.timestamp,
|
|
})
|
|
} catch (error) {
|
|
if (error instanceof UserNotFoundError) {
|
|
throw new TRPCError({ code: "NOT_FOUND", message: error.message })
|
|
}
|
|
throw error
|
|
}
|
|
}),
|
|
})
|
|
}
|