Initial commit: Lageplan v1.0 - Next.js 15.5, React 19
This commit is contained in:
44
src/app/api/tenants/by-slug/[slug]/route.ts
Normal file
44
src/app/api/tenants/by-slug/[slug]/route.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
|
||||
// Public endpoint: get tenant info by slug (logo, name)
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { slug: string } }
|
||||
) {
|
||||
try {
|
||||
const tenant = await (prisma as any).tenant.findUnique({
|
||||
where: { slug: params.slug },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
logoUrl: true,
|
||||
isActive: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!tenant) {
|
||||
return NextResponse.json({ error: 'Mandant nicht gefunden' }, { status: 404 })
|
||||
}
|
||||
|
||||
if (!tenant.isActive) {
|
||||
return NextResponse.json({
|
||||
error: 'Mandant gesperrt',
|
||||
reason: 'suspended',
|
||||
tenant: { name: tenant.name, slug: tenant.slug, logoUrl: tenant.logoUrl },
|
||||
}, { status: 403 })
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
tenant: {
|
||||
name: tenant.name,
|
||||
slug: tenant.slug,
|
||||
logoUrl: tenant.logoUrl,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching tenant by slug:', error)
|
||||
return NextResponse.json({ error: 'Serverfehler' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user