From 6179b5e8f426e111a97341ffeeb7ee25c8065eb8 Mon Sep 17 00:00:00 2001 From: Ronnie Beggs Date: Wed, 18 Oct 2023 21:09:39 -0700 Subject: [PATCH] [cleanup] create parseCase query helper function. --- .gitignore | 1 - src/supabase/queries/cases.ts | 36 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 10e71aea..f8532194 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ # dependencies node_modules/ -package-lock.json # Expo .expo/ diff --git a/src/supabase/queries/cases.ts b/src/supabase/queries/cases.ts index 65a93a27..2b66c012 100644 --- a/src/supabase/queries/cases.ts +++ b/src/supabase/queries/cases.ts @@ -48,20 +48,7 @@ export async function getCasesByIds(caseIds: CaseUid[]): Promise { } // cast raw sql data as CaseCardProps data type - return data.map(item => { - const formattedCase: Case = { - id: item.id, - approved: item.approved, - title: item.title, - summary: item.summary, - image: item.image, - caseSite: item.caseSite, - classClaimLink: item.classClaimLink, - individualClaimLink: item.individualClaimLink, - caseStatus: item.caseStatus, - }; - return formattedCase; - }); + return data.map(item => parseCase(item)); } catch (error) { // eslint-disable-next-line no-console console.warn('(getCasesByIds)', error); @@ -69,6 +56,27 @@ export async function getCasesByIds(caseIds: CaseUid[]): Promise { } } +/** + * Parse supabase case query and return Case object. + * + * @param item Case query result + * @returns `Case` object + */ +function parseCase(item: any): Case { + const formattedCase: Case = { + id: item.id, + approved: item.approved, + title: item.title, + summary: item.summary, + image: item.image, + caseSite: item.caseSite, + classClaimLink: item.classClaimLink, + individualClaimLink: item.individualClaimLink, + caseStatus: item.caseStatus, + }; + return formattedCase; +} + export async function addCase() { const dummyCase = { approved: false,