Fix DELETE handler to support async params

The DELETE API route now expects params as a Promise and awaits it to extract the conversation id. All references to params.id have been updated to use the resolved id variable.
This commit is contained in:
Christopher
2026-01-27 14:03:53 -08:00
parent 374f707dbf
commit cb141a91a1
@@ -11,7 +11,7 @@ import { getSession } from '@/lib/auth';
export async function DELETE( export async function DELETE(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: Promise<{ id: string }> }
) { ) {
try { try {
if (!db) { if (!db) {
@@ -23,13 +23,14 @@ export async function DELETE(
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
const { id } = await params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const deleteFor = searchParams.get('deleteFor'); // 'self' or 'both' const deleteFor = searchParams.get('deleteFor'); // 'self' or 'both'
// Verify the conversation belongs to this user // Verify the conversation belongs to this user
const conversation = await db.query.chatConversations.findFirst({ const conversation = await db.query.chatConversations.findFirst({
where: and( where: and(
eq(chatConversations.id, params.id), eq(chatConversations.id, id),
eq(chatConversations.participant1Id, session.user.id) eq(chatConversations.participant1Id, session.user.id)
), ),
}); });
@@ -40,7 +41,7 @@ export async function DELETE(
if (deleteFor === 'both') { if (deleteFor === 'both') {
// Delete the entire conversation and all messages (cascade will handle messages) // Delete the entire conversation and all messages (cascade will handle messages)
await db.delete(chatConversations).where(eq(chatConversations.id, params.id)); await db.delete(chatConversations).where(eq(chatConversations.id, id));
// TODO: Send a federation message to the other party to delete their copy // TODO: Send a federation message to the other party to delete their copy
// This would require implementing a swarm protocol for conversation deletion // This would require implementing a swarm protocol for conversation deletion
@@ -52,7 +53,7 @@ export async function DELETE(
} else { } else {
// Delete for self only - just delete the conversation record // Delete for self only - just delete the conversation record
// The other party will still have their copy // The other party will still have their copy
await db.delete(chatConversations).where(eq(chatConversations.id, params.id)); await db.delete(chatConversations).where(eq(chatConversations.id, id));
return NextResponse.json({ return NextResponse.json({
success: true, success: true,