Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: queries to add and remove single or multiple trees #2

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/supabase/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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(
AlexWang05 marked this conversation as resolved.
Show resolved Hide resolved
trees: { species: string; quantity: number }[],
) {
const { error } = await supabase.rpc('add_multiple_trees', {
AlexWang05 marked this conversation as resolved.
Show resolved Hide resolved
trees: JSON.stringify(trees),
});

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', {
p_tree_ids: treeIds,
AlexWang05 marked this conversation as resolved.
Show resolved Hide resolved
});

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