-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: queries to add and remove single or multiple trees (#2)
* supabase queries to add and remove trees. * query testing.
- Loading branch information
1 parent
9467743
commit 154cc08
Showing
1 changed file
with
44 additions
and
0 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,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}`); | ||
} | ||
} |