-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat-files.ts
50 lines (41 loc) · 1.01 KB
/
chat-files.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
import { supabase } from "@/lib/supabase/browser-client"
import { TablesInsert } from "@/supabase/types"
export const getChatFilesByChatId = async (chatId: string) => {
const { data: chatFiles, error } = await supabase
.from("chats")
.select(
`
id,
name,
files (*)
`
)
.eq("id", chatId)
.single()
if (!chatFiles) {
throw new Error(error.message)
}
return chatFiles
}
export const createChatFile = async (chatFile: TablesInsert<"chat_files">) => {
const { data: createdChatFile, error } = await supabase
.from("chat_files")
.insert(chatFile)
.select("*")
if (!createdChatFile) {
throw new Error(error.message)
}
return createdChatFile
}
export const createChatFiles = async (
chatFiles: TablesInsert<"chat_files">[]
) => {
const { data: createdChatFiles, error } = await supabase
.from("chat_files")
.insert(chatFiles)
.select("*")
if (!createdChatFiles) {
throw new Error(error.message)
}
return createdChatFiles
}