diff --git a/src/app/api/dealApi.ts b/src/app/api/dealApi.ts
index bdb5365..a9efe64 100644
--- a/src/app/api/dealApi.ts
+++ b/src/app/api/dealApi.ts
@@ -1,5 +1,4 @@
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
-import { getCurrentUserID } from "./userApi";
export type Deal = {
deal_amount: number;
@@ -7,9 +6,14 @@ export type Deal = {
investor_id: string;
};
-export async function getDealList() {
+export async function getDealList(userId: string | undefined) {
+ if (!userId) {
+ // console.error("No deal list of this user was found");
+ return; // Exit on error
+ }
+
const supabase = createSupabaseClient();
- // get id of investor who invests in the business
+ // get id of investors who invest in the business
const { data: dealData, error: dealError } = await supabase
.from("business")
.select(
@@ -21,11 +25,11 @@ export async function getDealList() {
)
`
)
- .eq("user_id", await getCurrentUserID())
+ .eq("user_id", userId)
.single();
if (dealError) {
- alert(JSON.stringify(dealError));
+ // alert(JSON.stringify(dealError));
console.error("Error fetching deal list:", dealError);
return; // Exit on error
}
@@ -56,13 +60,19 @@ export async function getDealList() {
return; // Exit on error
}
+ console.log(sortedDealData)
return sortedDealData;
}
// #TODO fix query to be non unique
-export async function getRecentDealData() {
+export async function getRecentDealData(userId: string | undefined) {
+ if (!userId) {
+ console.error("User not found");
+ return; // Exit on error
+ }
+
const supabase = createSupabaseClient();
- const dealList = await getDealList();
+ const dealList = await getDealList(userId);
if (!dealList) {
// #TODO div error
@@ -100,6 +110,8 @@ export async function getRecentDealData() {
const recentDealData = recentDealList.map((item, index) => {
return { ...item, ...recentUserData[index] };
});
+
+
return recentDealData;
}
@@ -121,8 +133,6 @@ export function convertToGraphData(deals: Deal[]): Record
{
// Create a sorted graph data object
const sortedGraphData: Record = {};
- sortedKeys.forEach((key) => {
- sortedGraphData[key] = graphData[key];
- });
+ sortedKeys.forEach((key) => {sortedGraphData[key] = graphData[key]});
return sortedGraphData;
}
diff --git a/src/app/dashboard/hook.ts b/src/app/dashboard/hook.ts
index e2a7ccf..236c4bc 100644
--- a/src/app/dashboard/hook.ts
+++ b/src/app/dashboard/hook.ts
@@ -1,13 +1,15 @@
import { useEffect, useState } from "react";
import { Deal, getDealList, convertToGraphData, getRecentDealData } from "../api/dealApi";
import { RecentDealData } from "@/components/recent-funds";
+import { getCurrentUserID } from "../api/userApi";
// custom hook for deal list
export function useDealList() {
const [dealList, setDealList] = useState();
const fetchDealList = async () => {
- setDealList(await getDealList());
+ // set the state to the deal list of current business user
+ setDealList(await getDealList(await getCurrentUserID()));
}
useEffect(() => {
@@ -21,7 +23,8 @@ export function useGraphData() {
const [graphData, setGraphData] = useState({});
const fetchGraphData = async () => {
- const dealList = await getDealList();
+ // fetch the state to the deal list of current business user
+ const dealList = await getDealList(await getCurrentUserID());
if (dealList) {
setGraphData(convertToGraphData(dealList));
}
@@ -38,7 +41,8 @@ export function useRecentDealData() {
const [recentDealData, setRecentDealData] = useState();
const fetchRecentDealData = async () => {
- setRecentDealData(await getRecentDealData());
+ // set the state to the deal list of current business user
+ setRecentDealData(await getRecentDealData(await getCurrentUserID()));
}
useEffect(() => {
diff --git a/src/app/project/apply/page.tsx b/src/app/project/apply/page.tsx
index b14b662..0509058 100644
--- a/src/app/project/apply/page.tsx
+++ b/src/app/project/apply/page.tsx
@@ -18,7 +18,7 @@ const BUCKET_PITCH_APPLICATION_NAME = "project-application";
export default function ApplyProject() {
const [isSuccess, setIsSuccess] = useState(true);
const onSubmit: SubmitHandler = async (data) => {
- alert("มาแน้ววว");
+ // alert("มาแน้ววว");
await sendApplication(data);
// console.table(data);
// console.log(typeof data["projectPhotos"], data["projectPhotos"]);
diff --git a/src/lib/data/projectQuery.ts b/src/lib/data/projectQuery.ts
index 568b5da..ecdf23e 100644
--- a/src/lib/data/projectQuery.ts
+++ b/src/lib/data/projectQuery.ts
@@ -6,28 +6,28 @@ async function getTopProjects(client: SupabaseClient, numberOfRecords: number =
.from("project")
.select(
`
- id,
- project_name,
- business_id,
- published_time,
- project_short_description,
- card_image_url,
- project_investment_detail (
- min_investment,
- total_investment,
- target_investment,
- investment_deadline
- ),
- project_tag (
- tag (
- id,
- value
- )
- ),
- business (
- location
+ id,
+ project_name,
+ business_id,
+ published_time,
+ project_short_description,
+ card_image_url,
+ project_investment_detail (
+ min_investment,
+ total_investment,
+ target_investment,
+ investment_deadline
+ ),
+ project_tag (
+ tag (
+ id,
+ value
)
- `
+ ),
+ business (
+ location
+ )
+ `
)
.order("published_time", { ascending: false })
.limit(numberOfRecords);
@@ -89,6 +89,9 @@ async function getProjectData(client: SupabaseClient, projectId: number) {
...tag!inner (
tag_name:value
)
+ ),
+ business (
+ user_id
)
`
)