Skip to content

Commit

Permalink
complete testing of query functions, change uuid handling of multiple…
Browse files Browse the repository at this point in the history
… trees
  • Loading branch information
AlexWang05 committed Oct 12, 2024
1 parent ebb481e commit bea151a
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/supabase/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,44 @@ import { supabase } from './client';

// Function to add a single tree
export async function addTree(species: string) {
const { data, error } = await supabase.rpc('add_tree', { species });
const { error } = await supabase.rpc('add_tree', { species });

if (error) {
throw new Error(`Error adding tree: ${error.message}`);
}

return data;
}

// Function to add multiple trees
export async function addMultipleTrees(species: string, quantity: number) {
const { data, error } = await supabase.rpc('add_multiple_trees', {
species,
quantity,
export async function addMultipleTrees(
trees: { species: string; quantity: number }[],
) {
const { error } = await supabase.rpc('add_multiple_trees', {
trees: JSON.stringify(trees),
});

if (error) {
throw new Error(`Error adding multiple trees: ${error.message}`);
}

return data;
}

// Function to remove a single tree by UUID
export async function removeTree(treeId: string) {
const { data, error } = await supabase.rpc('remove_tree', {
tree_id: treeId,
const { error } = await supabase.rpc('remove_tree', {
tree_uuid: treeId,
});

if (error) {
throw new Error(`Error removing tree: ${error.message}`);
}

return data;
}

// Function to remove multiple trees by a list of UUIDs
export async function removeMultipleTrees(treeIds: string[]) {
const { data, error } = await supabase.rpc('remove_multiple_trees', {
tree_ids: treeIds,
const { error } = await supabase.rpc('remove_multiple_trees', {
p_tree_ids: treeIds,
});

if (error) {
throw new Error(`Error removing multiple trees: ${error.message}`);
}

return data;
}
}

0 comments on commit bea151a

Please sign in to comment.