This commit is contained in:
2026-04-11 23:30:14 +02:00
parent 10ca8c3e8c
commit b73939d381
1574 changed files with 621 additions and 57974 deletions

View File

@@ -76,6 +76,7 @@ export async function POST(request: NextRequest) {
// We must exclude 'id', 'offers', 'owner', 'createdAt', 'updatedAt' from the data object
const cleanData: any = {
name: data.name || "Nouvelle Entreprise",
slug: data.slug || null,
category: data.category || "Autre",
location: data.location || "Ma Ville",
description: data.description || "",
@@ -93,6 +94,21 @@ export async function POST(request: NextRequest) {
founderImageUrl: data.founderImageUrl || null,
keyMetric: data.keyMetric || null,
}
// 2. Slug Uniqueness Check
if (cleanData.slug) {
const slugConflict = await prisma.business.findFirst({
where: {
slug: cleanData.slug,
NOT: { ownerId: ownerId } // Important: allow the owner to keep their own slug
}
});
if (slugConflict) {
return NextResponse.json({
error: `Le lien personnalisé "${cleanData.slug}" est déjà utilisé par une autre entreprise. Veuillez en choisir un autre.`
}, { status: 400 });
}
}
let business;
const existing = await prisma.business.findFirst({