Skip to content

Commit

Permalink
use Omit<UserPlant> for add details query
Browse files Browse the repository at this point in the history
  • Loading branch information
ccatherinetan committed Dec 23, 2024
1 parent 76e9059 commit 057b35d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion api/supabase/queries/userPlants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { UUID } from 'crypto';
import { UserPlant } from '@/types/schema';
import supabase from '../createClient';

export async function insertUserPlants(userPlants: Partial<UserPlant>[]) {
export async function insertUserPlants(
userPlants: Omit<UserPlant, 'id' | 'date_removed'>[],
) {
const { error } = await supabase.from('user_plants').insert(userPlants);
if (error) throw new Error(`Error inserting user plants: ${error.message}`);
}
Expand Down
11 changes: 7 additions & 4 deletions app/add-details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ export default function Home() {
// instead of doing userId!
if (!userId) return;
try {
const completedDetails: Partial<UserPlant>[] = details.map(detail => ({
...detail,
userId: userId,
}));
const completedDetails: Omit<UserPlant, 'id' | 'date_removed'>[] =
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) {
Expand Down

0 comments on commit 057b35d

Please sign in to comment.