chore: add prettier with config and format all files
This commit is contained in:
@@ -5,7 +5,8 @@ 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 { item_key, item_key_is_regex, combinator, signal_type, condition, threshold, active } =
|
||||
body;
|
||||
|
||||
const result = await pool.query(
|
||||
`UPDATE alerts SET
|
||||
@@ -29,4 +30,4 @@ export const DELETE = withAuth(async (_req: NextRequest, { 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 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,10 @@ export const GET = withAuth(async () => {
|
||||
if (alertsResult.rows.length === 0) return NextResponse.json([]);
|
||||
|
||||
const latestResult = await pool.query<{
|
||||
combinator: string; item_key: string; green: number; red: number;
|
||||
combinator: string;
|
||||
item_key: string;
|
||||
green: number;
|
||||
red: number;
|
||||
}>(
|
||||
`SELECT DISTINCT ON (combinator, item_key) combinator, item_key, green, red
|
||||
FROM signals
|
||||
@@ -22,9 +25,7 @@ export const GET = withAuth(async () => {
|
||||
|
||||
const localeMap = getServerLocaleMap();
|
||||
|
||||
const latestMap = new Map(
|
||||
latestResult.rows.map(r => [`${r.combinator}::${r.item_key}`, r]),
|
||||
);
|
||||
const latestMap = new Map(latestResult.rows.map((r) => [`${r.combinator}::${r.item_key}`, r]));
|
||||
|
||||
const triggered: TriggeredAlert[] = [];
|
||||
|
||||
@@ -49,14 +50,15 @@ export const GET = withAuth(async () => {
|
||||
|
||||
const value = alert.signal_type === 'green' ? vals.green : vals.red;
|
||||
const fired = alert.condition === 'above' ? value > alert.threshold : value < alert.threshold;
|
||||
if (fired) triggered.push({
|
||||
...alert,
|
||||
current_value: value,
|
||||
combinator_match: combinator,
|
||||
matched_item_key: item_key,
|
||||
});
|
||||
if (fired)
|
||||
triggered.push({
|
||||
...alert,
|
||||
current_value: value,
|
||||
combinator_match: combinator,
|
||||
matched_item_key: item_key,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(triggered);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,15 +10,16 @@ export const GET = withAuth(async () => {
|
||||
export const POST = withAuth(async (req: NextRequest) => {
|
||||
const body = await req.json();
|
||||
const {
|
||||
item_key, item_key_is_regex = false,
|
||||
combinator = null, signal_type = 'green', condition, threshold,
|
||||
item_key,
|
||||
item_key_is_regex = false,
|
||||
combinator = null,
|
||||
signal_type = 'green',
|
||||
condition,
|
||||
threshold,
|
||||
} = body;
|
||||
|
||||
if (!item_key || !condition || threshold === undefined) {
|
||||
return NextResponse.json(
|
||||
{ error: 'item_key, condition, threshold required' },
|
||||
{ status: 400 },
|
||||
);
|
||||
return NextResponse.json({ error: 'item_key, condition, threshold required' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await pool.query(
|
||||
@@ -27,4 +28,4 @@ export const POST = withAuth(async (req: NextRequest) => {
|
||||
[item_key, item_key_is_regex, combinator, signal_type, condition, threshold],
|
||||
);
|
||||
return NextResponse.json(result.rows[0], { status: 201 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user