blob: b07a0a3ae80e0ec2139e4ee6260c32228c011283 (
plain) (
blame)
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
|
import sb from '../../sb';
export interface UserNotifications {
created_at: string;
updated_at: string;
user_id: number;
subscription: JSON;
}
export const getUserSubscription = async (userId: number) =>
await sb.from('user_notifications').select('*').eq('user_id', userId);
export const getUserSubscriptions = async () => {
const { data, error } = await sb.from('user_notifications').select('*');
if (error) return [];
return data as UserNotifications[];
};
export const deleteUserSubscription = async (userId: number) =>
await sb.from('user_notifications').delete().eq('user_id', userId);
export const setUserSubscription = async (userId: number, subscription: JSON) =>
await sb.from('user_notifications').upsert(
{
user_id: userId,
updated_at: new Date().toISOString(),
subscription: subscription
},
{ onConflict: 'user_id' }
);
|