feat: implement core platform features including business directory, admin dashboard, authentication, and API infrastructure
Some checks failed
Build and Push App / build (push) Failing after 16m2s
Some checks failed
Build and Push App / build (push) Failing after 16m2s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '../../../lib/prisma'
|
||||
import prisma from '@/lib/prisma'
|
||||
|
||||
// GET /api/offers — optionally filter by businessId
|
||||
export async function GET(request: NextRequest) {
|
||||
@@ -26,6 +26,44 @@ export async function GET(request: NextRequest) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { businessId } = body
|
||||
|
||||
if (!businessId) {
|
||||
return NextResponse.json({ error: 'businessId manquant' }, { status: 400 })
|
||||
}
|
||||
|
||||
// 1. Fetch business and their plan's limit
|
||||
const business = await prisma.business.findUnique({
|
||||
where: { id: businessId },
|
||||
include: {
|
||||
_count: { select: { offers: true } }
|
||||
}
|
||||
})
|
||||
|
||||
if (!business) {
|
||||
return NextResponse.json({ error: 'Entreprise non trouvée' }, { status: 404 })
|
||||
}
|
||||
|
||||
// Fetch the specific limit for this tier from the database
|
||||
const planDetails = await prisma.pricingPlan.findUnique({
|
||||
where: { tier: business.plan }
|
||||
})
|
||||
|
||||
if (!planDetails) {
|
||||
return NextResponse.json({ error: 'Configuration du forfait introuvable' }, { status: 500 })
|
||||
}
|
||||
|
||||
// 2. Enforce limits
|
||||
const currentCount = business._count.offers
|
||||
const offerLimit = planDetails.offerLimit
|
||||
|
||||
if (currentCount >= offerLimit) {
|
||||
return NextResponse.json({
|
||||
error: `Limite d'offres atteinte (${offerLimit} max pour le plan ${planDetails.name}). Veuillez passer au plan supérieur pour publier plus d'offres.`
|
||||
}, { status: 403 })
|
||||
}
|
||||
|
||||
// 3. Create offer
|
||||
const offer = await prisma.offer.create({
|
||||
data: body,
|
||||
include: { business: true },
|
||||
|
||||
Reference in New Issue
Block a user