Initial commit

This commit is contained in:
Haitham Khalifa
2026-02-16 12:18:06 +01:00
commit b538d84e17
63 changed files with 15059 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
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 });
}
}