refactor: rename all database field to snake_case

This commit is contained in:
sirin 2024-10-14 00:12:41 +07:00
parent d8a2f13d6c
commit 0d14e15d13
6 changed files with 97 additions and 89 deletions

View File

@ -81,7 +81,7 @@ const CheckoutPage = ({
} else { } else {
try { try {
const supabase = createSupabaseClient(); const supabase = createSupabaseClient();
const { data, error } = await supabase.from("InvestmentDeal").insert([ const { data, error } = await supabase.from("investment_deal").insert([
{ {
investorId: investor_id, investorId: investor_id,
projectId: project_id, projectId: project_id,

View File

@ -25,15 +25,15 @@ const TopProjects = async () => {
{topProjectsData.map((project) => ( {topProjectsData.map((project) => (
<Link href={`/deals/${project.id}`} key={project.id}> <Link href={`/deals/${project.id}`} key={project.id}>
<ProjectCard <ProjectCard
name={project.projectName} name={project.project_name}
description={project.projectShortDescription} description={project.project_short_description}
imageUri={project.cardImage} imageUri={project.card_image_url}
joinDate={new Date(project.publishedTime).toLocaleDateString()} joinDate={new Date(project.published_time).toLocaleDateString()}
location={project.Business.location} location={project.business.location}
tags={project.ItemTag.map((item) => item.Tag.value)} tags={project.item_tag.map((item) => item.tag.value)}
minInvestment={project.ProjectInvestmentDetail[0]?.minInvestment || 0} minInvestment={project.project_investment_detail[0]?.min_investment || 0}
totalInvestor={0} totalInvestor={0}
totalRaised={project.ProjectInvestmentDetail[0]?.totalInvestment || 0} totalRaised={project.project_investment_detail[0]?.total_investment || 0}
/> />
</Link> </Link>
))} ))}

View File

@ -1,16 +1,15 @@
import { SupabaseClient } from "@supabase/supabase-js"; import { SupabaseClient } from "@supabase/supabase-js";
function getAllTagsQuery(client: SupabaseClient) { function getAllTagsQuery(client: SupabaseClient) {
return client.from("Tag").select("id, value"); return client.from("tag").select("id, value");
} }
function getALlFundedStatusQuery(client: SupabaseClient) { function getALlFundedStatusQuery(client: SupabaseClient) {
return client.from("FundedStatus").select("id, value, description"); return client.from("funded_status").select("id, value, description");
} }
function getAllBusinessTypeQuery(client: SupabaseClient) { function getAllBusinessTypeQuery(client: SupabaseClient) {
return client.from("BusinessType").select("id, value, description"); return client.from("business_type").select("id, value, description");
} }
export { getAllTagsQuery, getALlFundedStatusQuery, getAllBusinessTypeQuery }; export { getAllBusinessTypeQuery, getALlFundedStatusQuery, getAllTagsQuery };

View File

@ -6,33 +6,33 @@ async function getTopProjects(
) { ) {
try { try {
const { data, error } = await client const { data, error } = await client
.from("Project") .from("project")
.select( .select(
` `
id, id,
projectName, project_name,
businessId, business_id,
publishedTime, published_time,
projectShortDescription, project_short_description,
cardImage, card_image_url,
ProjectInvestmentDetail ( project_investment_detail (
minInvestment, min_investment,
totalInvestment, total_investment,
targetInvestment, target_investment,
investmentDeadline investment_deadline
), ),
ItemTag ( item_tag (
Tag ( tag (
id, id,
value value
) )
), ),
Business ( business (
location location
) )
`, `,
) )
.order("publishedTime", { ascending: false }) .order("published_time", { ascending: false })
.limit(numberOfRecords); .limit(numberOfRecords);
if (error) { if (error) {
@ -48,20 +48,20 @@ async function getTopProjects(
} }
function getProjectDataQuery(client: SupabaseClient, projectId: number) { function getProjectDataQuery(client: SupabaseClient, projectId: number) {
return client.from("Project").select( return client.from("project").select(
` `
project_name:projectName, project_name,
project_short_description:projectShortDescription, project_short_description,
project_description:projectDescription, project_description,
published_time:publishedTime, published_time,
...ProjectInvestmentDetail!inner ( ...project_investment_detail!inner (
min_investment:minInvestment, min_investment,
total_investment:totalInvestment, total_investment,
target_investment:targetInvestment, target_investment,
investment_deadline:investmentDeadline investment_deadline
), ),
tags:ItemTag!inner ( tags:item_tag!inner (
...Tag!inner ( ...tag!inner (
tag_name:value tag_name:value
) )
) )
@ -70,20 +70,20 @@ function getProjectDataQuery(client: SupabaseClient, projectId: number) {
} }
async function getProjectData(client: SupabaseClient, projectId: number) { async function getProjectData(client: SupabaseClient, projectId: number) {
const query = client.from("Project").select( const query = client.from("project").select(
` `
project_name:projectName, project_name,
project_short_description:projectShortDescription, project_short_description,
project_description:projectDescription, project_description,
published_time:publishedTime, published_time,
...ProjectInvestmentDetail!inner ( ...project_investment_detail!inner (
min_investment:minInvestment, min_investment,
total_investment:totalInvestment, total_investment,
target_investment:targetInvestment, target_investment,
investment_deadline:investmentDeadline investment_deadline
), ),
tags:ItemTag!inner ( tags:item_tag!inner (
...Tag!inner ( ...tag!inner (
tag_name:value tag_name:value
) )
) )
@ -123,35 +123,35 @@ function searchProjectsQuery(
const start = (page - 1) * pageSize; const start = (page - 1) * pageSize;
const end = start + pageSize - 1; const end = start + pageSize - 1;
let query = client.from("Project").select( let query = client.from("project").select(
` `
project_id:id, project_id:id,
project_name:projectName, project_name,
published_time:publishedTime, published_time,
project_short_description:projectShortDescription, project_short_description,
card_image_url:cardImage, card_image_url,
...ProjectStatus!Project_projectStatusId_fkey!inner ( ...project_status!project_project_status_id_fkey!inner (
project_status:value project_status:value
), ),
...ProjectInvestmentDetail!inner ( ...project_investment_detail!inner (
min_investment:minInvestment, min_investment,
total_investment:totalInvestment, total_investment,
target_investment:targetInvestment, target_investment,
investment_deadline:investmentDeadline investment_deadline
), ),
tags:ItemTag!inner ( tags:item_tag!inner (
...Tag!inner ( ...tag!inner (
tag_name:value tag_name:value
) )
), ),
...Business!inner ( ...business!inner (
...businessType!inner ( ...business_type!inner (
business_type:value business_type:value
), ),
business_location:location business_location:location
) )
`, `,
).order("publishedTime", { ascending: false }).range(start, end); ).order("published_time", { ascending: false }).range(start, end);
if (sortByTimeFilter === "all") { if (sortByTimeFilter === "all") {
sortByTimeFilter = undefined; sortByTimeFilter = undefined;
@ -170,19 +170,19 @@ function searchProjectsQuery(
} }
if (searchTerm) { if (searchTerm) {
query = query.ilike("projectName", `%${searchTerm}%`); query = query.ilike("project_name", `%${searchTerm}%`);
} }
if (tagsFilter) { if (tagsFilter) {
query = query.in("ItemTag.Tag.value", tagsFilter); query = query.in("item_tag.tag.value", tagsFilter);
} }
if (projectStatus) { if (projectStatus) {
query = query.eq("ProjectStatus.value", projectStatus); query = query.eq("project_status.value", projectStatus);
} }
if (businessTypeFilter) { if (businessTypeFilter) {
query = query.eq("Business.businessType.value", businessTypeFilter); query = query.eq("business.business_type.value", businessTypeFilter);
} }
return query; return query;

View File

@ -1,35 +1,44 @@
import { SupabaseClient } from "@supabase/supabase-js"; import { SupabaseClient } from "@supabase/supabase-js";
function getBusinesses(client: SupabaseClient, query: string | null) { function getBusinesses(client: SupabaseClient, query: string | null) {
return client.from("Business").select("id, businessName, joinedDate").ilike("businessName", `%${query}%`); return client.from("business").select("id, business_name, joined_date").ilike(
"business_name",
`%${query}%`,
);
} }
function getProjects(client: SupabaseClient, businessIds: string[]) { function getProjects(client: SupabaseClient, businessIds: string[]) {
return client return client
.from("Project") .from("project")
.select( .select(
` `
id, id,
projectName, project_name,
businessId, business_id,
publishedTime, published_time,
projectShortDescription, project_short_description,
ProjectInvestmentDetail ( project_investment_detail (
minInvestment, min_investment,
totalInvestment, total_investment,
targetInvestment target_investment
) )
` `,
) )
.in("businessId", businessIds); .in("business_id", businessIds);
} }
function getTags(client: SupabaseClient, projectIds: string[]) { function getTags(client: SupabaseClient, projectIds: string[]) {
return client.from("ItemTag").select("itemId, Tag (value)").in("itemId", projectIds); return client.from("item_tag").select("item_id, tag (value)").in(
"item_id",
projectIds,
);
} }
function getInvestmentCounts(client: SupabaseClient, projectIds: string[]) { function getInvestmentCounts(client: SupabaseClient, projectIds: string[]) {
return client.from("InvestmentDeal").select("*", { count: "exact", head: true }).in("projectId", projectIds); return client.from("investment_deal").select("*", {
count: "exact",
head: true,
}).in("project_id", projectIds);
} }
export { getBusinesses, getProjects, getTags, getInvestmentCounts }; export { getBusinesses, getInvestmentCounts, getProjects, getTags };

View File

@ -3,7 +3,7 @@ import { SupabaseClient } from "@supabase/supabase-js";
async function getUserProfile(client: SupabaseClient, userId: string) { async function getUserProfile(client: SupabaseClient, userId: string) {
try { try {
const { data, error } = await client const { data, error } = await client
.from("Profiles") .from("profiles")
.select("updated_at, username, full_name, avatar_url, website, bio") .select("updated_at, username, full_name, avatar_url, website, bio")
.eq("id", userId) .eq("id", userId)
.single(); .single();