fix: force dynamic for meeting page
This commit is contained in:
48
app/api/objectives/route.ts
Normal file
48
app/api/objectives/route.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { supabase } from '@/lib/supabase';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const projectId = searchParams.get('project_id');
|
||||
|
||||
let query = supabase.from('objectives').select('*').order('period_start', { ascending: false });
|
||||
|
||||
if (projectId) {
|
||||
query = query.eq('project_id', projectId);
|
||||
}
|
||||
|
||||
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 { project_id, title, description, period_start, period_end, created_by } = body;
|
||||
|
||||
if (!project_id || !title || !period_start || !period_end) {
|
||||
return NextResponse.json({ error: '项目ID、标题、开始日期和结束日期为必填项' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (new Date(period_end) < new Date(period_start)) {
|
||||
return NextResponse.json({ error: '结束日期不能早于开始日期' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('objectives')
|
||||
.insert({ project_id, title, description, period_start, period_end, created_by })
|
||||
.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