-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathget-default-team.ts
More file actions
55 lines (47 loc) · 1.14 KB
/
get-default-team.ts
File metadata and controls
55 lines (47 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'server-only'
import { l } from '@/lib/clients/logger/logger'
import { supabaseAdmin } from '@/lib/clients/supabase/admin'
import { serializeError } from 'serialize-error'
export async function getDefaultTeamRelation(userId: string) {
const { data, error } = await supabaseAdmin
.from('users_teams')
.select('*')
.eq('user_id', userId)
.eq('is_default', true)
if (error || data.length === 0) {
l.error({
key: 'get_default_team_relation:error',
error: serializeError(error),
user_id: userId,
})
throw new Error('No default team found')
}
return data[0]!
}
export async function getDefaultTeam(userId: string) {
const { data, error } = await supabaseAdmin
.from('users_teams')
.select(
`
team_id,
teams (
id,
name,
slug
)
`
)
.eq('user_id', userId)
.eq('is_default', true)
.single()
if (error || !data) {
l.error({
key: 'GET_DEFAULT_TEAM:ERROR',
message: error?.message,
error: serializeError(error),
user_id: userId,
})
throw new Error('No default team found')
}
return data.teams
}