synchronisation du contenu avec la DB et amélioration du CMS
- Migration du blog et des interviews des données mockées vers PostgreSQL (Prisma). - Refonte des pages publiques en Server Components pour de meilleures performances/SEO. - Intégration d'un éditeur de texte riche (React Quill) avec titres H1-H6 et séparateurs. - Correction des erreurs de validation Prisma liées aux paramètres asynchrones (Next.js 15+). - Correction des problèmes d'affichage des modales de suspension via React Portals. - Installation de @tailwindcss/typography et correction du débordement de texte (break-words). - Implémentation des actions de modération (suspension/révocation) pour les utilisateurs et boutiques.
This commit is contained in:
35
app/api/conversations/[id]/archive/route.ts
Normal file
35
app/api/conversations/[id]/archive/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const userId = request.headers.get('x-user-id')
|
||||
const { id } = await 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 })
|
||||
}
|
||||
}
|
||||
60
app/api/conversations/[id]/route.ts
Normal file
60
app/api/conversations/[id]/route.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
// GET /api/conversations/[id] — Get messages for a conversation
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const userId = request.headers.get('x-user-id')
|
||||
const { id } = await params
|
||||
|
||||
if (!userId) {
|
||||
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 })
|
||||
}
|
||||
|
||||
// Verify user is a participant
|
||||
const isParticipant = await prisma.conversationParticipant.findUnique({
|
||||
where: {
|
||||
userId_conversationId: {
|
||||
userId: userId,
|
||||
conversationId: id
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!isParticipant) {
|
||||
return NextResponse.json({ error: 'Accès non autorisé' }, { status: 403 })
|
||||
}
|
||||
|
||||
const messages = await prisma.message.findMany({
|
||||
where: { conversationId: id },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
include: {
|
||||
sender: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
avatar: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Mark messages as read (where sender is not the current user)
|
||||
await prisma.message.updateMany({
|
||||
where: {
|
||||
conversationId: id,
|
||||
senderId: { not: userId },
|
||||
read: false
|
||||
},
|
||||
data: { read: true }
|
||||
})
|
||||
|
||||
return NextResponse.json(messages)
|
||||
} catch (error) {
|
||||
console.error('GET /api/conversations/[id] error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
60
app/api/conversations/route.ts
Normal file
60
app/api/conversations/route.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
|
||||
// GET /api/conversations — List all conversations for the user
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const userId = request.headers.get('x-user-id')
|
||||
|
||||
if (!userId) {
|
||||
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 })
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const businessId = searchParams.get('businessId')
|
||||
|
||||
const conversations = await prisma.conversation.findMany({
|
||||
where: {
|
||||
participants: {
|
||||
some: { userId: userId }
|
||||
},
|
||||
...(businessId ? { businessId: businessId } : {})
|
||||
},
|
||||
include: {
|
||||
business: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
logoUrl: true,
|
||||
slug: true,
|
||||
ownerId: true
|
||||
}
|
||||
},
|
||||
participants: {
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
avatar: true,
|
||||
role: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
messages: {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 1
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: 'desc'
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json(conversations)
|
||||
} catch (error) {
|
||||
console.error('GET /api/conversations error:', error)
|
||||
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user