Files
sitemente/app/api/research/route.ts
T
horus d5575b58e3 SiteMente - AI-Powered Lead Generation Platform
Features:
- Mission Control dashboard
- HP Submissions tracking
- AI Agents integration
- Lead management CRM
- Marketing email templates
- Chrome extension support

Tech: Next.js, TypeScript, Tailwind CSS, MySQL
2026-03-19 17:38:12 +01:00

65 lines
1.9 KiB
TypeScript

import { NextResponse } from 'next/server';
import mysql from 'mysql2/promise';
const dbConfig = {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'sitemente',
password: process.env.DB_PASS || 'SiteMente2026!',
database: process.env.DB_NAME || 'sitemente'
};
export async function GET() {
let conn;
try {
conn = await mysql.createConnection(dbConfig);
const [rows] = await conn.execute('SELECT * FROM research ORDER BY created_at DESC');
return NextResponse.json(rows);
} catch (e) {
console.error(e);
return NextResponse.json([]);
} finally {
if (conn) conn.end();
}
}
export async function POST(request: Request) {
let conn;
try {
const body = await request.json();
conn = await mysql.createConnection(dbConfig);
await conn.execute(
'INSERT INTO research (name, query, results_count, summary, results, created_at) VALUES (?, ?, ?, ?, ?, NOW())',
[body.name, body.query, body.results_count || 0, body.summary || '', JSON.stringify(body.results || [])]
);
const [rows] = await conn.execute('SELECT * FROM research ORDER BY created_at DESC');
return NextResponse.json(rows);
} catch (e) {
console.error(e);
return NextResponse.json({ error: 'Failed to save research' }, { status: 500 });
} finally {
if (conn) conn.end();
}
}
export async function DELETE(request: Request) {
let conn;
try {
const { searchParams } = new URL(request.url);
const id = searchParams.get('id');
if (!id) return NextResponse.json({ error: 'Missing id' }, { status: 400 });
conn = await mysql.createConnection(dbConfig);
await conn.execute('DELETE FROM research WHERE id = ?', [id]);
return NextResponse.json({ success: true });
} catch (e) {
console.error(e);
return NextResponse.json({ error: 'Failed to delete' }, { status: 500 });
} finally {
if (conn) conn.end();
}
}