mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
fix: use objects as params for multiple props
This commit is contained in:
parent
93fb407bd9
commit
0bc45f18d0
@ -19,7 +19,7 @@ function FindContent() {
|
|||||||
data: businesses,
|
data: businesses,
|
||||||
isLoading: isLoadingBusinesses,
|
isLoading: isLoadingBusinesses,
|
||||||
error: businessError,
|
error: businessError,
|
||||||
} = useQuery(getBusinessAndProject(supabase, query));
|
} = useQuery(getBusinessAndProject(supabase, { businessName: query }));
|
||||||
|
|
||||||
const isLoading = isLoadingBusinesses;
|
const isLoading = isLoadingBusinesses;
|
||||||
const error = businessError;
|
const error = businessError;
|
||||||
|
|||||||
@ -1,6 +1,27 @@
|
|||||||
import { SupabaseClient } from "@supabase/supabase-js";
|
import { SupabaseClient } from "@supabase/supabase-js";
|
||||||
|
|
||||||
export const getBusinessAndProject = (client: SupabaseClient, businessName: String | null) => {
|
export const getAllBusinesses = (client: SupabaseClient) => {
|
||||||
|
return client.from("business").select(`
|
||||||
|
id,
|
||||||
|
location,
|
||||||
|
business_name,
|
||||||
|
...business_type (
|
||||||
|
business_type:value
|
||||||
|
),
|
||||||
|
joined_date,
|
||||||
|
...user_id (
|
||||||
|
user_id:id,
|
||||||
|
username,
|
||||||
|
full_name,
|
||||||
|
email
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBusinessAndProject = (
|
||||||
|
client: SupabaseClient,
|
||||||
|
params: { businessName?: String | null; businessId?: number | null; single?: boolean } = { single: false }
|
||||||
|
) => {
|
||||||
const query = client.from("business").select(`
|
const query = client.from("business").select(`
|
||||||
business_id:id,
|
business_id:id,
|
||||||
location,
|
location,
|
||||||
@ -31,8 +52,17 @@ export const getBusinessAndProject = (client: SupabaseClient, businessName: Stri
|
|||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (businessName && businessName.trim() !== "") {
|
if (params.businessName && params.businessName.trim() !== "") {
|
||||||
return query.ilike("business_name", `%${businessName}%`);
|
return query.ilike("business_name", `%${params.businessName}%`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.businessId) {
|
||||||
|
query.eq("id", params.businessId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.single) {
|
||||||
|
query.single();
|
||||||
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user