diff --git a/app/api/family-notes/[family]/route.ts b/app/api/family-notes/[family]/route.ts index eea89ac..08b365d 100644 --- a/app/api/family-notes/[family]/route.ts +++ b/app/api/family-notes/[family]/route.ts @@ -1,43 +1,6 @@ import { NextRequest, NextResponse } from 'next/server'; import { auth } from '@/lib/auth'; -import { getGraphQLClient } from '@/lib/graphql/client'; - -interface FamilyResearchNote { - id: string; - familyName: string; - content: string; - updatedAt: string; -} - -interface FamilyNoteQueryResponse { - familyResearchNote: FamilyResearchNote | null; -} - -interface UpsertFamilyNoteMutationResponse { - upsertFamilyResearchNote: FamilyResearchNote; -} - -const FAMILY_NOTE_QUERY = ` - query FamilyResearchNote($familyName: String!) { - familyResearchNote(familyName: $familyName) { - id - familyName - content - updatedAt - } - } -`; - -const UPSERT_FAMILY_NOTE_MUTATION = ` - mutation UpsertFamilyResearchNote($input: FamilyResearchNoteInput!) { - upsertFamilyResearchNote(input: $input) { - id - familyName - content - updatedAt - } - } -`; +import { pool } from '@/lib/pool'; export async function GET( request: NextRequest, @@ -50,30 +13,25 @@ export async function GET( } const { family } = await params; - const client = getGraphQLClient(); - const { data, errors } = await client.request(FAMILY_NOTE_QUERY, { - familyName: family.toUpperCase(), - }); + const familyName = family.toUpperCase(); - if (errors) { - console.error('GraphQL errors:', errors); - return NextResponse.json( - { error: 'Failed to fetch family note' }, - { status: 500 } - ); - } + const { rows } = await pool.query( + `SELECT family_name, content, updated_at FROM family_research_notes WHERE family_name = $1`, + [familyName] + ); - if (!data?.familyResearchNote) { + if (rows.length === 0) { return NextResponse.json( { error: 'Family notes not found' }, { status: 404 } ); } + const note = rows[0]; return NextResponse.json({ - family: data.familyResearchNote.familyName, - content: data.familyResearchNote.content, - lastModified: data.familyResearchNote.updatedAt, + family: note.family_name, + content: note.content, + lastModified: note.updated_at.toISOString(), }); } catch (error: any) { console.error('Error reading family notes:', error); @@ -95,6 +53,7 @@ export async function PUT( } const { family } = await params; + const familyName = family.toUpperCase(); const { content } = await request.json(); if (typeof content !== 'string') { @@ -104,27 +63,24 @@ export async function PUT( ); } - const client = getGraphQLClient(); - const { data, errors } = await client.request(UPSERT_FAMILY_NOTE_MUTATION, { - input: { - familyName: family.toUpperCase(), - content, - }, - }, { - 'x-user-id': session.user.id!, - }); + const { rows } = await pool.query( + `UPDATE family_research_notes + SET content = $1, updated_by = $2, updated_at = NOW() + WHERE family_name = $3 + RETURNING updated_at`, + [content, session.user.id, familyName] + ); - if (errors) { - console.error('GraphQL errors:', errors); + if (rows.length === 0) { return NextResponse.json( - { error: 'Failed to update family notes' }, - { status: 500 } + { error: 'Family notes not found' }, + { status: 404 } ); } return NextResponse.json({ success: true, - lastModified: data?.upsertFamilyResearchNote.updatedAt, + lastModified: rows[0].updated_at.toISOString(), }); } catch (error) { console.error('Error updating family notes:', error); diff --git a/app/family-notes/[family]/page.tsx b/app/family-notes/[family]/page.tsx index 92710f9..957da6a 100644 --- a/app/family-notes/[family]/page.tsx +++ b/app/family-notes/[family]/page.tsx @@ -5,6 +5,7 @@ export const metadata: Metadata = { title: 'Family Research Notes', }; -export default function FamilyNotePage({ params }: { params: { family: string } }) { - return ; +export default async function FamilyNotePage({ params }: { params: Promise<{ family: string }> }) { + const { family } = await params; + return ; }