migrate: replace Firebase with PostgreSQL across core routes
- chat-context.ts: session history now from fs_sessions - /api/sessions: reads from fs_sessions (NextAuth session auth) - /api/github/connect: NextAuth session + stores in fs_users.data - /api/user/api-key: NextAuth session + stores in fs_users.data - /api/projects/[id]/vision: PATCH to fs_projects JSONB - /api/projects/[id]/knowledge/items: reads from fs_knowledge_items - /api/projects/[id]/knowledge/import-ai-chat: uses pg createKnowledgeItem - lib/server/knowledge.ts: fully rewritten to use PostgreSQL - entrypoint.sh: add fs_knowledge_items and chat_conversations tables Made-with: Cursor
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAdminDb } from '@/lib/firebase/admin';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth/authOptions';
|
||||
import { query } from '@/lib/db-postgres';
|
||||
|
||||
/**
|
||||
* Save vision answers to Firestore
|
||||
*/
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { projectId } = await params;
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.email) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { visionAnswers } = body;
|
||||
|
||||
@@ -20,29 +24,41 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
|
||||
const adminDb = getAdminDb();
|
||||
const rows = await query<{ id: string; data: any }>(
|
||||
`SELECT p.id, p.data FROM fs_projects p
|
||||
JOIN fs_users u ON u.id = p.user_id
|
||||
WHERE p.id = $1 AND u.data->>'email' = $2 LIMIT 1`,
|
||||
[projectId, session.user.email]
|
||||
);
|
||||
|
||||
// Save vision answers and mark ready for MVP
|
||||
await adminDb.collection('projects').doc(projectId).set(
|
||||
{
|
||||
visionAnswers: {
|
||||
q1: visionAnswers.q1,
|
||||
q2: visionAnswers.q2,
|
||||
q3: visionAnswers.q3,
|
||||
allAnswered: true,
|
||||
updatedAt: visionAnswers.updatedAt || new Date().toISOString(),
|
||||
},
|
||||
readyForMVP: true,
|
||||
currentPhase: 'mvp',
|
||||
phaseStatus: 'ready',
|
||||
if (rows.length === 0) {
|
||||
return NextResponse.json({ error: 'Project not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const current = rows[0].data ?? {};
|
||||
const updated = {
|
||||
...current,
|
||||
visionAnswers: {
|
||||
q1: visionAnswers.q1,
|
||||
q2: visionAnswers.q2,
|
||||
q3: visionAnswers.q3,
|
||||
allAnswered: true,
|
||||
updatedAt: visionAnswers.updatedAt || new Date().toISOString(),
|
||||
},
|
||||
{ merge: true }
|
||||
readyForMVP: true,
|
||||
currentPhase: 'mvp',
|
||||
phaseStatus: 'ready',
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
await query(
|
||||
`UPDATE fs_projects SET data = $1::jsonb WHERE id = $2`,
|
||||
[JSON.stringify(updated), projectId]
|
||||
);
|
||||
|
||||
console.log(`[Vision API] Saved vision answers for project ${projectId}`);
|
||||
|
||||
// Trigger MVP generation (async - don't wait)
|
||||
console.log(`[Vision API] Triggering MVP generation for project ${projectId}...`);
|
||||
fetch(new URL(`/api/projects/${projectId}/mvp-checklist`, request.url).toString(), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -65,4 +81,3 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user