76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import {
|
|
deleteCallTask,
|
|
getCallTask,
|
|
updateCallTask,
|
|
} from '@/lib/firestore';
|
|
import { Timestamp } from 'firebase/firestore';
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: { id: string } }
|
|
) {
|
|
try {
|
|
// TODO: Get userId from auth token
|
|
const userId = 'test-user-id'; // Replace with actual auth
|
|
const task = await getCallTask(params.id);
|
|
|
|
if (!task || task.userId !== userId) {
|
|
return NextResponse.json({ error: 'Task not found' }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({ task });
|
|
} catch (error) {
|
|
console.error('Error fetching call task:', error);
|
|
return NextResponse.json({ error: 'Failed to fetch task' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function PATCH(
|
|
request: NextRequest,
|
|
{ params }: { params: { id: string } }
|
|
) {
|
|
try {
|
|
const body = await request.json();
|
|
// TODO: Get userId from auth token
|
|
const userId = 'test-user-id'; // Replace with actual auth
|
|
|
|
const existing = await getCallTask(params.id);
|
|
if (!existing || existing.userId !== userId) {
|
|
return NextResponse.json({ error: 'Task not found' }, { status: 404 });
|
|
}
|
|
|
|
const updates: Record<string, unknown> = { ...body };
|
|
if (updates.scheduledAt) {
|
|
updates.scheduledAt = Timestamp.fromDate(new Date(updates.scheduledAt as string));
|
|
}
|
|
|
|
await updateCallTask(params.id, updates);
|
|
const task = await getCallTask(params.id);
|
|
return NextResponse.json({ task });
|
|
} catch (error) {
|
|
console.error('Error updating call task:', error);
|
|
return NextResponse.json({ error: 'Failed to update task' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(
|
|
request: NextRequest,
|
|
{ params }: { params: { id: string } }
|
|
) {
|
|
try {
|
|
// TODO: Get userId from auth token
|
|
const userId = 'test-user-id'; // Replace with actual auth
|
|
const existing = await getCallTask(params.id);
|
|
if (!existing || existing.userId !== userId) {
|
|
return NextResponse.json({ error: 'Task not found' }, { status: 404 });
|
|
}
|
|
|
|
await deleteCallTask(params.id);
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
console.error('Error deleting call task:', error);
|
|
return NextResponse.json({ error: 'Failed to delete task' }, { status: 500 });
|
|
}
|
|
}
|