import { type NextRequest, NextResponse } from 'next/server'; import { withAuth } from '@/lib/apiHelpers'; import pool from '@/lib/db'; export const PUT = withAuth(async (req: NextRequest, { params }) => { const { id } = await params; const body = await req.json(); const { item_key, item_key_is_regex, combinator, signal_type, condition, threshold, active } = body; const result = await pool.query( `UPDATE alerts SET item_key = COALESCE($1, item_key), item_key_is_regex = COALESCE($2, item_key_is_regex), combinator = $3, signal_type = COALESCE($4, signal_type), condition = COALESCE($5, condition), threshold = COALESCE($6, threshold), active = COALESCE($7, active) WHERE id = $8 RETURNING *`, [item_key, item_key_is_regex, combinator, signal_type, condition, threshold, active, id], ); if (result.rowCount === 0) return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json(result.rows[0]); }); export const DELETE = withAuth(async (_req: NextRequest, { params }) => { const { id } = await params; const result = await pool.query('DELETE FROM alerts WHERE id = $1', [id]); if (result.rowCount === 0) return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json({ ok: true }); });