Initial web
This commit is contained in:
32
web/app/api/alerts/[id]/route.ts
Normal file
32
web/app/api/alerts/[id]/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import pool from '@/lib/db';
|
||||
import { withAuth } from '@/lib/apiHelpers';
|
||||
|
||||
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 });
|
||||
});
|
||||
Reference in New Issue
Block a user