This repository was archived by the owner on May 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { CreateGiftDTO , GiftIdea } from '@/features/gifts/types' ;
2
+ import supabase from '@/services/supabaseClient' ;
3
+
4
+ export const fetchGifts = async ( ) : Promise < GiftIdea [ ] > => {
5
+ const { data, error } = await supabase . from ( 'gifts' ) . select ( '*' ) ;
6
+ if ( error ) throw error ;
7
+ return data as GiftIdea [ ] ;
8
+ } ;
9
+
10
+ export const addGift = async ( gift : CreateGiftDTO ) : Promise < GiftIdea > => {
11
+ const { data, error } = await supabase . from ( 'gifts' ) . insert ( [ gift ] ) . single ( ) ;
12
+ if ( error ) throw error ;
13
+ return data as GiftIdea ;
14
+ } ;
15
+
16
+ export const deleteGift = async ( id : string ) : Promise < void > => {
17
+ const { error } = await supabase . from ( 'gifts' ) . delete ( ) . eq ( 'id' , id ) ;
18
+ if ( error ) throw error ;
19
+ } ;
20
+
21
+ export const updateGift = async (
22
+ gift : Partial < GiftIdea > ,
23
+ ) : Promise < GiftIdea > => {
24
+ const { data, error } = await supabase
25
+ . from ( 'gifts' )
26
+ . update ( gift )
27
+ . eq ( 'id' , gift . id )
28
+ . select ( '*' )
29
+ . single ( ) ;
30
+
31
+ if ( error ) {
32
+ console . error ( 'Supabase updateGift error:' , error ) ;
33
+ throw error ;
34
+ }
35
+
36
+ console . log ( 'Supabase updateGift response:' , data ) ;
37
+ return data as GiftIdea ;
38
+ } ;
Original file line number Diff line number Diff line change
1
+ import { CreateRecipientDTO , Recipient } from '@/features/recipients/types' ;
2
+ import supabase from '@/services/supabaseClient' ;
3
+
4
+ export const fetchRecipients = async ( ) : Promise < Recipient [ ] > => {
5
+ const { data, error } = await supabase . from ( 'recipients' ) . select ( '*' ) ;
6
+ if ( error ) throw error ;
7
+ return data as Recipient [ ] ;
8
+ } ;
9
+
10
+ export const addRecipient = async (
11
+ recipient : CreateRecipientDTO ,
12
+ ) : Promise < Recipient > => {
13
+ const { data, error } = await supabase
14
+ . from ( 'recipients' )
15
+ . insert ( [ recipient ] )
16
+ . single ( ) ;
17
+ if ( error ) throw error ;
18
+ return data as Recipient ;
19
+ } ;
20
+
21
+ export const deleteRecipient = async ( id : string ) : Promise < void > => {
22
+ const { error } = await supabase . from ( 'recipients' ) . delete ( ) . eq ( 'id' , id ) ;
23
+ if ( error ) throw error ;
24
+ } ;
25
+
26
+ export const findRecipientById = async ( id : number ) : Promise < string | null > => {
27
+ const { data, error } = await supabase
28
+ . from ( 'recipients' )
29
+ . select ( 'name' )
30
+ . eq ( 'id' , id )
31
+ . single ( ) ;
32
+
33
+ if ( error ) {
34
+ console . error ( 'Error fetching recipient:' , error ) ;
35
+ return null ;
36
+ }
37
+
38
+ return data ?. name || null ;
39
+ } ;
You can’t perform that action at this time.
0 commit comments