-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor user application checks and move related functions to …
…a new query module
- Loading branch information
Showing
2 changed files
with
41 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { SupabaseClient } from "@supabase/supabase-js"; | ||
|
||
export const hasUserApplied = async (supabase: SupabaseClient, userID: string) => { | ||
let { data: business, error } = await supabase.from("business").select("*").eq("user_id", userID); | ||
let { data: businessApplication, error: applicationError } = await supabase | ||
.from("business_application") | ||
.select("*") | ||
.eq("user_id", userID); | ||
// console.table(business); | ||
if (error || applicationError) { | ||
console.error(error); | ||
console.error(applicationError); | ||
} | ||
if ((business && business.length > 0) || (businessApplication && businessApplication.length > 0)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
export const transformChoice = (data: any) => { | ||
// convert any yes and no to true or false | ||
const transformedData = Object.entries(data).reduce((acc: Record<any, any>, [key, value]) => { | ||
if (typeof value === "string") { | ||
const lowerValue = value.toLowerCase(); | ||
if (lowerValue === "yes") { | ||
acc[key] = true; | ||
} else if (lowerValue === "no") { | ||
acc[key] = false; | ||
} else { | ||
acc[key] = value; // keep other string values unchanged | ||
} | ||
} else { | ||
acc[key] = value; // keep other types unchanged | ||
} | ||
return acc; | ||
}, {}); | ||
return transformedData; | ||
}; | ||
|