diff --git a/packages/api/src/trpc/routers/health/tracking.ts b/packages/api/src/trpc/routers/health/tracking.ts index b29e64e..ee6d5c7 100644 --- a/packages/api/src/trpc/routers/health/tracking.ts +++ b/packages/api/src/trpc/routers/health/tracking.ts @@ -2,6 +2,7 @@ import { schema } from "@hellth/db"; import { TRPCError } from "@trpc/server"; import { and, eq } from "drizzle-orm"; import { z } from "zod"; +import { handleToSlug } from "../../../lib/handle"; import { protectedProcedure, router } from "../../init"; import { addDays, @@ -428,17 +429,32 @@ export const trackingRouter = router({ const users = userIds.length ? await ctx.db.query.user.findMany({ where: (row, { inArray: rowInArray }) => rowInArray(row.id, userIds), - columns: { id: true, name: true, email: true }, + columns: { + id: true, + name: true, + username: true, + discriminator: true, + profileVisible: true, + }, }) : []; const userById = new Map(users.map((user) => [user.id, user])); - const scores = new Map(); + const scores = new Map< + string, + { userKey: string; name: string; handleSlug: string | null; points: number; completed: number } + >(); for (const log of logs) { if (log.points <= 0) continue; const user = userById.get(log.userId); + // Handle-Link nur fuer oeffentlich sichtbare Profile, sonst waere er + // ein toter Link (Profilseite liefert dann NOT_FOUND). + const handleSlug = user?.profileVisible + ? handleToSlug(user.username, user.discriminator) + : null; const current = scores.get(log.userId) ?? { userKey: log.userId, - name: user?.name || user?.email || "Hellth User", + name: user?.name || "Hellth User", + handleSlug, points: 0, completed: 0, };