All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 7m10s
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import "server-only";
|
|
import { z } from "zod";
|
|
import { admin } from "./supabase";
|
|
|
|
const uuidSchema = z.string().uuid();
|
|
|
|
export async function publicProfile(userId: string) {
|
|
const validId = uuidSchema.safeParse(userId);
|
|
if (!validId.success) return null;
|
|
|
|
const result = await admin()
|
|
.from("profiles")
|
|
.select(
|
|
"id,display_name,bio,avatar_path,profile_effect,name_glow,glow_color,role,bug_finder,custom_prefix,custom_prefix_icon,created_at",
|
|
)
|
|
.eq("id", validId.data)
|
|
.eq("account_status", "active")
|
|
.maybeSingle();
|
|
if (result.error) throw new Error(result.error.message);
|
|
if (!result.data) return null;
|
|
|
|
const [games, maps] = await Promise.all([
|
|
admin()
|
|
.from("game_sessions")
|
|
.select("id", { count: "exact", head: true })
|
|
.eq("owner_id", validId.data)
|
|
.eq("current_round", 5),
|
|
admin()
|
|
.from("datasets")
|
|
.select("id", { count: "exact", head: true })
|
|
.eq("owner_id", validId.data)
|
|
.eq("state", "published"),
|
|
]);
|
|
if (games.error) throw new Error(games.error.message);
|
|
if (maps.error) throw new Error(maps.error.message);
|
|
return {
|
|
...result.data,
|
|
completedGames: games.count ?? 0,
|
|
publishedMaps: maps.count ?? 0,
|
|
};
|
|
}
|