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:
2026-04-12 18:59:20 +02:00
parent b73939d381
commit 887030ee47
84 changed files with 5577 additions and 15128 deletions

View File

@@ -0,0 +1,52 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '../../../../../lib/prisma'
// POST /api/messages/[id]/report — Report a message for moderation
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const userId = request.headers.get('x-user-id')
const { id } = await params
const { reason } = await request.json()
if (!userId) {
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 })
}
// Verify message exists
const message = await prisma.message.findUnique({
where: { id }
})
if (!message) {
return NextResponse.json({ error: 'Message introuvable' }, { status: 404 })
}
// Check if user already reported this message
const existingReport = await prisma.messageReport.findFirst({
where: {
messageId: id,
reporterId: userId
}
})
if (existingReport) {
return NextResponse.json({ error: 'Vous avez déjà signalé ce message' }, { status: 400 })
}
const report = await prisma.messageReport.create({
data: {
messageId: id,
reporterId: userId,
reason: reason || 'Non spécifié'
}
})
return NextResponse.json(report)
} catch (error) {
console.error('POST /api/messages/[id]/report error:', error)
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
}
}

115
app/api/messages/route.ts Normal file
View File

@@ -0,0 +1,115 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '../../../lib/prisma'
// POST /api/messages — Send a message or start a conversation
export async function POST(request: NextRequest) {
try {
const userId = request.headers.get('x-user-id')
const { businessId, conversationId, content } = await request.json()
if (!userId) {
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 })
}
if (!content) {
return NextResponse.json({ error: 'Contenu manquant' }, { status: 400 })
}
let conversation;
let receiverId;
let finalBusinessId = businessId;
if (conversationId) {
// Case 1: Reply to an existing conversation
conversation = await prisma.conversation.findUnique({
where: { id: conversationId },
include: { participants: true }
});
if (!conversation) {
return NextResponse.json({ error: 'Conversation introuvable' }, { status: 404 });
}
const isParticipant = conversation.participants.some(p => p.userId === userId);
if (!isParticipant) {
return NextResponse.json({ error: 'Vous n\'êtes pas participant à cette conversation' }, { status: 403 });
}
// Find the other participant to determine receiverId
const otherParticipant = conversation.participants.find(p => p.userId !== userId);
receiverId = otherParticipant?.userId;
finalBusinessId = conversation.businessId;
} else if (businessId) {
// Case 2: Start a new conversation via business profile
const business = await prisma.business.findUnique({
where: { id: businessId },
select: { ownerId: true }
})
if (!business) {
return NextResponse.json({ error: 'Entreprise introuvable' }, { status: 404 })
}
receiverId = business.ownerId
if (userId === receiverId) {
return NextResponse.json({ error: 'Vous ne pouvez pas vous envoyer un message à vous-même' }, { status: 400 })
}
// Find or create a conversation for this user + business
conversation = await prisma.conversation.findFirst({
where: {
businessId: businessId,
participants: {
every: {
userId: { in: [userId, receiverId] }
}
}
}
})
if (!conversation) {
conversation = await prisma.conversation.create({
data: {
businessId: businessId,
participants: {
create: [
{ userId: userId },
{ userId: receiverId }
]
}
}
})
}
} else {
return NextResponse.json({ error: 'ID Business ou ID Conversation manquant' }, { status: 400 })
}
// 3. Create the message
const message = await prisma.message.create({
data: {
content,
senderId: userId,
conversationId: conversation.id
}
})
// 4. Update conversation updatedAt timestamp AND reset archive status for all
await prisma.$transaction([
prisma.conversation.update({
where: { id: conversation.id },
data: { updatedAt: new Date() }
}),
prisma.conversationParticipant.updateMany({
where: { conversationId: conversation.id },
data: { isArchived: false }
})
])
return NextResponse.json(message)
} catch (error) {
console.error('POST /api/messages error:', error)
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
}
}

View File

@@ -0,0 +1,29 @@
import { NextRequest, NextResponse } from 'next/server'
import prisma from '../../../../lib/prisma'
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 unreadCount = await prisma.message.count({
where: {
conversation: {
participants: {
some: { userId: userId }
}
},
senderId: { not: userId },
read: false
}
})
return NextResponse.json({ count: unreadCount })
} catch (error) {
console.error('GET /api/messages/unread error:', error)
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
}
}