fix: force dynamic for meeting page
This commit is contained in:
67
app/api/metrics/[id]/route.ts
Normal file
67
app/api/metrics/[id]/route.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { supabase } from '@/lib/supabase';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { data, error } = await supabase
|
||||
.from('metrics')
|
||||
.select('*')
|
||||
.eq('id', params.id)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return NextResponse.json({ error: '指标不存在' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const body = await request.json();
|
||||
const { name, unit, direction, category, is_active } = body;
|
||||
|
||||
const updateData: Record<string, unknown> = { updated_at: new Date().toISOString() };
|
||||
if (name !== undefined) updateData.name = name;
|
||||
if (unit !== undefined) updateData.unit = unit;
|
||||
if (direction !== undefined) updateData.direction = direction;
|
||||
if (category !== undefined) updateData.category = category;
|
||||
if (is_active !== undefined) updateData.is_active = is_active;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('metrics')
|
||||
.update(updateData)
|
||||
.eq('id', params.id)
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { error } = await supabase
|
||||
.from('metrics')
|
||||
.delete()
|
||||
.eq('id', params.id);
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
48
app/api/metrics/route.ts
Normal file
48
app/api/metrics/route.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { supabase } from '@/lib/supabase';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const activeOnly = searchParams.get('active_only') === 'true';
|
||||
const category = searchParams.get('category');
|
||||
|
||||
let query = supabase.from('metrics').select('*').order('name', { ascending: true });
|
||||
|
||||
if (activeOnly) query = query.eq('is_active', true);
|
||||
if (category) query = query.eq('category', category);
|
||||
|
||||
const { data, error } = await query;
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
const { name, unit, direction, category } = body;
|
||||
|
||||
if (!name || !unit) {
|
||||
return NextResponse.json({ error: '名称和单位为必填项' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('metrics')
|
||||
.insert({
|
||||
name,
|
||||
unit,
|
||||
direction: direction || 'increase',
|
||||
category,
|
||||
is_active: true,
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json(data, { status: 201 });
|
||||
}
|
||||
Reference in New Issue
Block a user