diff options
| author | Fuwn <[email protected]> | 2024-02-11 15:45:56 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-11 15:45:56 -0800 |
| commit | a8417ece5d5d0f75a6215dbfd47f0cc2f691defd (patch) | |
| tree | 3b877afff20635f8acdcfe0fb09cb1c8581c4de4 /src/lib | |
| parent | refactor(database): rename event badges (diff) | |
| download | due.moe-a8417ece5d5d0f75a6215dbfd47f0cc2f691defd.tar.xz due.moe-a8417ece5d5d0f75a6215dbfd47f0cc2f691defd.zip | |
feat(database): config sync scaffolding
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Database/userConfiguration.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/Database/userConfiguration.ts b/src/lib/Database/userConfiguration.ts new file mode 100644 index 00000000..5e2f0c96 --- /dev/null +++ b/src/lib/Database/userConfiguration.ts @@ -0,0 +1,29 @@ +import supabase from './supabase'; + +interface UserConfiguration { + user_id: number; + configuration: any; + created_at: string; + updated_at: string; +} + +export const getUserConfiguration = async (userId: number) => { + const { data, error } = await supabase + .from('user_configuration') + .select('*') + .eq('user_id', userId); + + if (error || data.length === 0 || data[0].user_id !== userId) return null; + + return data[0] as UserConfiguration; +}; + +export const setUserConfiguration = async (userId: number, configuration: UserConfiguration) => { + const { data, error } = await supabase + .from('user_configuration') + .upsert({ user_id: userId, configuration }); + + if (error || !data || (data as []).length === 0) return null; + + return data[0] as UserConfiguration; +}; |