diff options
| author | Fuwn <[email protected]> | 2024-07-24 21:24:09 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-07-24 21:24:09 -0700 |
| commit | 8a94bbfba322f8011017980e4362d46c4d51bb55 (patch) | |
| tree | 4d861cd7f1d9304e6297e1b52fe759674fd5df1a /src/lib/Database/userNotifications.ts | |
| parent | feat(layout): browser notifications (diff) | |
| download | due.moe-8a94bbfba322f8011017980e4362d46c4d51bb55.tar.xz due.moe-8a94bbfba322f8011017980e4362d46c4d51bb55.zip | |
feat: background notifications
Diffstat (limited to 'src/lib/Database/userNotifications.ts')
| -rw-r--r-- | src/lib/Database/userNotifications.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/Database/userNotifications.ts b/src/lib/Database/userNotifications.ts new file mode 100644 index 00000000..c61c2aa7 --- /dev/null +++ b/src/lib/Database/userNotifications.ts @@ -0,0 +1,29 @@ +import supabase from './supabase'; + +export interface UserNotifications { + created_at: string; + updated_at: string; + user_id: number; + subscription: JSON; +} + +export const getUserSubscription = async (userId: number) => + await supabase.from('user_notifications').select('*').eq('user_id', userId); + +export const getUserSubscriptions = async () => { + const { data, error } = await supabase.from('user_notifications').select('*'); + + if (error) return []; + + return data as UserNotifications[]; +}; + +export const setUserSubscription = async (userId: number, subscription: JSON) => + await supabase.from('user_notifications').upsert( + { + user_id: userId, + updated_at: new Date().toISOString(), + subscription: subscription + }, + { onConflict: 'user_id' } + ); |