-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
457 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { supabaseClient } from '../utils/db' | ||
|
||
const sb = supabaseClient() | ||
|
||
export async function getMembers () { | ||
const { data, error } = await sb.from('ghmembers').select('*') | ||
if (error) throw error | ||
return data | ||
} | ||
|
||
export async function getTeams () { | ||
const { data, error } = await sb.from('ghteams').select('*') | ||
if (error) throw error | ||
return data | ||
} | ||
|
||
export async function getMembersForTeams () { | ||
const teams = await getTeams() | ||
const members = await getMembers() | ||
|
||
const memberMap = {} | ||
for (const member of members) { | ||
memberMap[member.id] = member | ||
} | ||
|
||
const teamMap = {} | ||
for (const team of teams) { | ||
teamMap[team.id] = team | ||
} | ||
|
||
const { data, error } = await sb.from('ghteammembers').select('*') | ||
|
||
if (error) throw error | ||
if (!data) return {} | ||
|
||
const membersForTeams = {} | ||
|
||
for (const team of teams) membersForTeams[teamMap[team.id].name] = [] | ||
|
||
for (const membership of data) { | ||
const member = memberMap[membership.member_id] | ||
const team = teamMap[membership.team_id] | ||
|
||
if (member && team) membersForTeams[team.name].push(member) | ||
} | ||
|
||
return membersForTeams | ||
} |
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,11 @@ | ||
import { createClient } from '@supabase/supabase-js' | ||
|
||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL | ||
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY | ||
|
||
|
||
const client = createClient(supabaseUrl, supabaseKey); | ||
|
||
export function supabaseClient() { | ||
return client; | ||
} |
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
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
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
Oops, something went wrong.