-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassistant-collections.ts
69 lines (57 loc) · 1.58 KB
/
assistant-collections.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { supabase } from "@/lib/supabase/browser-client"
import { TablesInsert } from "@/supabase/types"
export const getAssistantCollectionsByAssistantId = async (
assistantId: string
) => {
const { data: assistantCollections, error } = await supabase
.from("assistants")
.select(
`
id,
name,
collections (*)
`
)
.eq("id", assistantId)
.single()
if (!assistantCollections) {
throw new Error(error.message)
}
return assistantCollections
}
export const createAssistantCollection = async (
assistantCollection: TablesInsert<"assistant_collections">
) => {
const { data: createdAssistantCollection, error } = await supabase
.from("assistant_collections")
.insert(assistantCollection)
.select("*")
if (!createdAssistantCollection) {
throw new Error(error.message)
}
return createdAssistantCollection
}
export const createAssistantCollections = async (
assistantCollections: TablesInsert<"assistant_collections">[]
) => {
const { data: createdAssistantCollections, error } = await supabase
.from("assistant_collections")
.insert(assistantCollections)
.select("*")
if (!createdAssistantCollections) {
throw new Error(error.message)
}
return createdAssistantCollections
}
export const deleteAssistantCollection = async (
assistantId: string,
collectionId: string
) => {
const { error } = await supabase
.from("assistant_collections")
.delete()
.eq("assistant_id", assistantId)
.eq("collection_id", collectionId)
if (error) throw new Error(error.message)
return true
}