From 154cc085e4a70470e895ea5595a9f2fc42ba6482 Mon Sep 17 00:00:00 2001 From: Alex Wang <73456512+AlexWang05@users.noreply.github.com> Date: Sat, 26 Oct 2024 11:37:26 -0700 Subject: [PATCH] feat: queries to add and remove single or multiple trees (#2) * supabase queries to add and remove trees. * query testing. --- src/supabase/queries.ts | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/supabase/queries.ts diff --git a/src/supabase/queries.ts b/src/supabase/queries.ts new file mode 100644 index 0000000..3f44ceb --- /dev/null +++ b/src/supabase/queries.ts @@ -0,0 +1,44 @@ +import { supabase } from './client'; + +// Function to add a single tree +export async function addTree(species: string) { + const { error } = await supabase.rpc('add_tree', { species }); + + if (error) { + throw new Error(`Error adding tree: ${error.message}`); + } +} + +// Function to add multiple trees +export async function addMultipleTrees(species: string, quantity: number) { + const { error } = await supabase.rpc('add_multiple_trees', { + species: species, + quantity: quantity, + }); + + if (error) { + throw new Error(`Error adding multiple trees: ${error.message}`); + } +} + +// Function to remove a single tree by UUID +export async function removeTree(treeId: string) { + const { error } = await supabase.rpc('remove_tree', { + tree_uuid: treeId, + }); + + if (error) { + throw new Error(`Error removing tree: ${error.message}`); + } +} + +// Function to remove multiple trees by a list of UUIDs +export async function removeMultipleTrees(treeIds: string[]) { + const { error } = await supabase.rpc('remove_multiple_trees', { + tree_uuids: treeIds, + }); + + if (error) { + throw new Error(`Error removing multiple trees: ${error.message}`); + } +}