From 057b35d104b0249b75d8d45673b120077bf9bf38 Mon Sep 17 00:00:00 2001 From: Catherine Tan Date: Mon, 23 Dec 2024 00:39:12 -0800 Subject: [PATCH] use Omit for add details query --- api/supabase/queries/userPlants.ts | 4 +++- app/add-details/page.tsx | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/api/supabase/queries/userPlants.ts b/api/supabase/queries/userPlants.ts index db43a19..cc6e14d 100644 --- a/api/supabase/queries/userPlants.ts +++ b/api/supabase/queries/userPlants.ts @@ -2,7 +2,9 @@ import { UUID } from 'crypto'; import { UserPlant } from '@/types/schema'; import supabase from '../createClient'; -export async function insertUserPlants(userPlants: Partial[]) { +export async function insertUserPlants( + userPlants: Omit[], +) { const { error } = await supabase.from('user_plants').insert(userPlants); if (error) throw new Error(`Error inserting user plants: ${error.message}`); } diff --git a/app/add-details/page.tsx b/app/add-details/page.tsx index cd6ca0f..1b893f2 100644 --- a/app/add-details/page.tsx +++ b/app/add-details/page.tsx @@ -113,10 +113,13 @@ export default function Home() { // instead of doing userId! if (!userId) return; try { - const completedDetails: Partial[] = details.map(detail => ({ - ...detail, - userId: userId, - })); + const completedDetails: Omit[] = + details.map(detail => ({ + user_id: userId, + plant_id: detail.plant_id!, + date_added: detail.date_added!, + planting_type: detail.planting_type!, + })); await insertUserPlants(completedDetails); router.push('/view-plants'); } catch (error) {