-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bebbda
commit 747ac64
Showing
3 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Reactions } from './types'; | ||
import supabase from '../utils/supabase'; | ||
|
||
export async function addReactionToStory( | ||
input_profile_id: number, | ||
input_story_id: number, | ||
input_reaction_id: number, | ||
): Promise<void> { | ||
const { data, error } = await supabase.rpc('add_reaction_to_story', { | ||
story_id: input_story_id, | ||
profile_id: input_profile_id, | ||
reaction_id: input_reaction_id, | ||
}); | ||
if (error) { | ||
console.log(error); | ||
throw new Error( | ||
`An error occured when trying to insert author reaction to story: ${error}`, | ||
); | ||
} else { | ||
return data; | ||
} | ||
} | ||
|
||
export async function deleteReactionToStory( | ||
input_profile_id: number, | ||
input_story_id: number, | ||
input_reaction_id: number, | ||
): Promise<void> { | ||
const { data, error } = await supabase.rpc('remove_reaction_from_story', { | ||
story_id: input_story_id, | ||
profile_id: input_profile_id, | ||
reaction_id: input_reaction_id, | ||
}); | ||
if (error) { | ||
console.log(error); | ||
throw new Error( | ||
`An error occured when trying to delete reaction to story by a user: ${error}`, | ||
); | ||
} else { | ||
return data; | ||
} | ||
} | ||
|
||
export async function fetchStoryPreviewById( | ||
storyId: number, | ||
): Promise<StoryPreview[]> { | ||
const { data, error } = await supabase.rpc('fetch_story_preview_by_id', { | ||
input_story_id: storyId, | ||
}); | ||
if (error) { | ||
console.log(error); | ||
throw new Error( | ||
`An error occured when trying to fetch story preview by ID: ${error}`, | ||
); | ||
} else { | ||
return data; | ||
} | ||
} | ||
|
||
export async function fetchStoryPreviewById( | ||
storyId: number, | ||
): Promise<StoryPreview[]> { | ||
const { data, error } = await supabase.rpc('fetch_story_preview_by_id', { | ||
input_story_id: storyId, | ||
}); | ||
if (error) { | ||
console.log(error); | ||
throw new Error( | ||
`An error occured when trying to fetch story preview by ID: ${error}`, | ||
); | ||
} else { | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters