import type { NextApiRequest, NextApiResponse } from 'next' import { db, schema } from '../../../../lib/db/connection' import { eq } from 'drizzle-orm' export default async function handler( req: NextApiRequest, res: NextApiResponse ) { if (req.method !== 'PATCH') { return res.status(405).json({ error: 'Method not allowed' }) } const { id } = req.query const { status, risk_level, rejection_reason } = req.body if (!id || !status) { return res.status(400).json({ error: 'ID and status are required' }) } try { await db .update(schema.sources) .set({ status: status, riskLevel: risk_level || 0, rejectionReason: rejection_reason || null, updatedAt: new Date() }) .where(eq(schema.sources.id, parseInt(id as string))) return res.status(200).json({ success: true }) } catch (error) { console.error('Database error:', error) return res.status(500).json({ error: 'Internal server error' }) } }