fix: force dynamic for meeting page
This commit is contained in:
70
app/api/meetings/[id]/route.ts
Normal file
70
app/api/meetings/[id]/route.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
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('meetings')
|
||||
.select(`
|
||||
*,
|
||||
created_by_user:users!meetings_created_by_fkey(id, name, avatar_url),
|
||||
project:projects(id, name)
|
||||
`)
|
||||
.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 { summary, decisions, risks, next_period_commitments } = body;
|
||||
|
||||
const updateData: Record<string, unknown> = { updated_at: new Date().toISOString() };
|
||||
if (summary !== undefined) updateData.summary = summary;
|
||||
if (decisions !== undefined) updateData.decisions = decisions;
|
||||
if (risks !== undefined) updateData.risks = risks;
|
||||
if (next_period_commitments !== undefined) updateData.next_period_commitments = next_period_commitments;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('meetings')
|
||||
.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('meetings')
|
||||
.delete()
|
||||
.eq('id', params.id);
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
59
app/api/meetings/route.ts
Normal file
59
app/api/meetings/route.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
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('meetings')
|
||||
.select(`
|
||||
*,
|
||||
created_by_user:users!meetings_created_by_fkey(id, name, avatar_url),
|
||||
project:projects(id, name)
|
||||
`)
|
||||
.order('created_at', { 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, period_start, period_end, summary, decisions, risks, next_period_commitments, created_by } = body;
|
||||
|
||||
if (!project_id || !period_start || !period_end || !summary) {
|
||||
return NextResponse.json(
|
||||
{ error: '项目ID、周期开始日期、周期结束日期和总结为必填项' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('meetings')
|
||||
.insert({
|
||||
project_id,
|
||||
period_start,
|
||||
period_end,
|
||||
summary,
|
||||
decisions,
|
||||
risks,
|
||||
next_period_commitments,
|
||||
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