Add public profiles and cosmetic shop
All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 7m10s
All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 7m10s
This commit is contained in:
41
lib/public-profile.ts
Normal file
41
lib/public-profile.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user