Files
afrov2/app/api/conversations/[id]/archive/route.ts
streaper2 889e70bfc0
Some checks failed
Build and Push App / build (push) Failing after 21s
fix build
2026-04-15 22:40:04 +02:00

36 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import prisma from '../../../../../lib/prisma'
// PATCH /api/conversations/[id]/archive — Toggle archive status for the user
export async function PATCH(
request: NextRequest,
context: { params: Promise<{ id: string }> }
): Promise<Response> {
try {
const userId = request.headers.get('x-user-id')
const { id } = await context.params
const { archived } = await request.json()
if (!userId) {
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 })
}
const updatedParticipant = await prisma.conversationParticipant.update({
where: {
userId_conversationId: {
userId: userId,
conversationId: id
}
},
data: {
isArchived: archived ?? true
}
})
return NextResponse.json(updatedParticipant)
} catch (error) {
console.error('PATCH /api/conversations/[id]/archive error:', error)
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
}
}