+
+
+
- {props.name}
-
- {props.description}
-
-
- Joined {props.joinDate}
-
-
+
+ {props.business_name}
+
+
+
+ Joined {props.joined_date}
+
+
+
-
- {props.location}
-
- Technology
+
+ {props.location}
+
+ {props.business_type}
diff --git a/src/components/projectCard.tsx b/src/components/projectCard.tsx
index 3189ced..ff221f3 100644
--- a/src/components/projectCard.tsx
+++ b/src/components/projectCard.tsx
@@ -22,6 +22,18 @@ interface ProjectCardProps {
}
export function ProjectCard(props: ProjectCardProps) {
+ if (props.minInvestment === null) {
+ props.minInvestment = 0;
+ }
+
+ if (props.totalInvestor === null) {
+ props.minInvestment = 0;
+ }
+
+ if (props.totalRaised === null) {
+ props.minInvestment = 0;
+ }
+
return (
{
`);
};
+export const getBusinessByName = (
+ client: SupabaseClient,
+ params: { businessName?: string | null; single?: boolean } = { single: false }
+) => {
+ const query = client.from("business").select(`
+ business_id:id,
+ location,
+ business_name,
+ ...business_type (
+ business_type_id: id,
+ business_type: value
+ ),
+ joined_date,
+ user_id
+ `);
+
+ if (params.businessName && params.businessName.trim() !== "") {
+ query.ilike("business_name", `%${params.businessName}%`);
+ }
+
+ if (params.single) {
+ query.single();
+ }
+
+ return query;
+};
+
export const getBusinessAndProject = (
client: SupabaseClient,
params: { businessName?: String | null; businessId?: number | null; single?: boolean } = { single: false }
@@ -53,7 +80,7 @@ export const getBusinessAndProject = (
`);
if (params.businessName && params.businessName.trim() !== "") {
- return query.ilike("business_name", `%${params.businessName}%`);
+ return query.or(`business_name.ilike.%${params.businessName}%,project_name.ilike.%${params.businessName}%`);
}
if (params.businessId) {
diff --git a/src/lib/data/projectQuery.ts b/src/lib/data/projectQuery.ts
index 27ca3c3..9402632 100644
--- a/src/lib/data/projectQuery.ts
+++ b/src/lib/data/projectQuery.ts
@@ -1,4 +1,5 @@
import { SupabaseClient } from "@supabase/supabase-js";
+import { ProjectCardProps } from "@/types/ProjectCard";
async function getTopProjects(client: SupabaseClient, numberOfRecords: number = 4) {
try {
@@ -241,6 +242,62 @@ const getProjectByUserId = (client: SupabaseClient, userId: string) => {
.eq("business.user_id", userId);
};
+function getProjectByName(client: SupabaseClient, searchTerm: string) {
+ return client
+ .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
+ )
+ `
+ )
+ .ilike("project_name", `%${searchTerm}%`);
+}
+
+const getProjectCardData = async (client: SupabaseClient, projectIds: string[]) => {
+ const { data, error } = await client.from("project_card").select("*").in("project_id", projectIds);
+
+ if (error) {
+ return { data: null, error: error.message };
+ }
+
+ const projectSections = data.map((project) => {
+ const projectSection: ProjectCardProps = {
+ id: project.project_id,
+ project_name: project.project_name,
+ short_description: project.short_description,
+ image_url: project.image_url,
+ join_date: project.join_date,
+ location: project.location,
+ tags: project.tags || [],
+ min_investment: project.min_investment,
+ total_investor: project.total_investor,
+ total_raise: project.total_raise,
+ };
+ return projectSection;
+ });
+
+ return { data: projectSections, error: null };
+};
export {
getProjectData,
getProjectDataQuery,
@@ -248,4 +305,6 @@ export {
searchProjectsQuery,
getProjectByBusinessId,
getProjectByUserId,
+ getProjectByName,
+ getProjectCardData,
};
diff --git a/src/types/BusinessCard.ts b/src/types/BusinessCard.ts
new file mode 100644
index 0000000..1371428
--- /dev/null
+++ b/src/types/BusinessCard.ts
@@ -0,0 +1,7 @@
+export interface BusinessCardProps {
+ business_id: number;
+ business_name: string;
+ joined_date: string;
+ location: string;
+ business_type: string;
+}
diff --git a/src/types/ProjectCard.ts b/src/types/ProjectCard.ts
new file mode 100644
index 0000000..51e9955
--- /dev/null
+++ b/src/types/ProjectCard.ts
@@ -0,0 +1,12 @@
+export interface ProjectCardProps {
+ id?: number;
+ project_name: string;
+ short_description: string;
+ image_url: string;
+ join_date: string;
+ location: string;
+ tags: string[] | null;
+ min_investment: number;
+ total_investor: number;
+ total_raise: number;
+}
diff --git a/src/types/database.types.ts b/src/types/database.types.ts
index 57dc0ac..9169905 100644
Binary files a/src/types/database.types.ts and b/src/types/database.types.ts differ