(slug: string, userId?: string)
| 31 | import { fetchAllPages } from "@/utils/supabase/pagination"; |
| 32 | |
| 33 | async function fetchUserProfile(slug: string, userId?: string) { |
| 34 | const supabase = await createClient(); |
| 35 | |
| 36 | const query = supabase |
| 37 | .from("users") |
| 38 | .select( |
| 39 | "id, name, image, hero, status, bio, work, website, slug, social_x_link, created_at, public, follow_email, is_ambassador, is_following, follower_count, following_count", |
| 40 | ) |
| 41 | .eq("slug", slug); |
| 42 | |
| 43 | if (userId) { |
| 44 | query.eq("id", userId); |
| 45 | } else { |
| 46 | query.eq("public", true); |
| 47 | } |
| 48 | |
| 49 | const { data } = await query.single(); |
| 50 | |
| 51 | if (!data) { |
| 52 | return { |
| 53 | data: null, |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | const isOwner = userId && data.id === userId; |
| 58 | |
| 59 | return { |
| 60 | data: { |
| 61 | ...data, |
| 62 | follow_email: isOwner ? data.follow_email : undefined, |
| 63 | following_count: data?.following_count || 0, |
| 64 | followers_count: data?.follower_count || 0, |
| 65 | }, |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | async function getPublicUserProfile(slug: string) { |
| 70 | "use cache"; |
no test coverage detected