diff --git a/src/app/portfolio/[uid]/hook.ts b/src/app/portfolio/[uid]/hook.ts index 93f293d..faa5ab8 100644 --- a/src/app/portfolio/[uid]/hook.ts +++ b/src/app/portfolio/[uid]/hook.ts @@ -1,25 +1,34 @@ import { SupabaseClient } from "@supabase/supabase-js"; import { getProjectTag, getTagName } from "@/lib/data/query"; -async function getBusinessId(supabase: SupabaseClient, projectId: number) { - let { data: project, error } = await supabase +async function getBusinessTypeName( + supabase: SupabaseClient, + projectId: number +) { + let { data: project, error: projectError } = await supabase .from("project") .select("business_id") .eq("id", projectId); - if (error) { - console.error(error); + if (projectError) { + console.error(projectError); } - return project?.[0]?.business_id; -} -async function getBusinessType(supabase: SupabaseClient, businessId: number) { - let { data: business, error } = await supabase + + let { data: business, error: businessError } = await supabase .from("business") .select("business_type") - .eq("id", businessId); - if (error) { - console.error(error); + .eq("id", project?.[0]?.business_id); + if (businessError) { + console.error(businessError); } - return business?.[0]?.business_type; + + let { data: business_type, error: businessTypeError } = await supabase + .from("business_type") + .select("value") + .eq("id", business?.[0]?.business_type); + if (businessTypeError) { + console.error(businessError); + } + return business_type; } // only use deal that were made at most year ago @@ -194,6 +203,5 @@ export { dayOftheWeekData, getInvestorProjectTag, countTags, - getBusinessId, - getBusinessType, + getBusinessTypeName, }; diff --git a/src/app/portfolio/[uid]/page.tsx b/src/app/portfolio/[uid]/page.tsx index b13a9d0..8ce7b38 100644 --- a/src/app/portfolio/[uid]/page.tsx +++ b/src/app/portfolio/[uid]/page.tsx @@ -8,8 +8,7 @@ import { dayOftheWeekData, getInvestorProjectTag, countTags, - getBusinessId, - getBusinessType, + getBusinessTypeName, } from "./hook"; import CountUpComponent from "@/components/countUp"; @@ -31,16 +30,15 @@ export default async function Portfolio({ const dayOfWeekData = deals ? dayOftheWeekData(deals) : []; const tags = deals ? await getInvestorProjectTag(supabase, deals) : []; const tagCount = countTags(tags); - // get business id from project id - const investedBusinessIds = deals + // console.log(investedBusinessIds); + const businessType = deals ? await Promise.all( deals.map( - async (item) => await getBusinessId(supabase, item.project_id) + async (item) => await getBusinessTypeName(supabase, item.project_id) ) ) : []; - console.log(investedBusinessIds); - // console.log(tags); + console.log(businessType); // console.log(tagCount); return (