lomavuokraus/app/api/listings/check-slug/route.ts
2025-11-29 20:13:17 +02:00

18 lines
533 B
TypeScript

import { NextResponse } from 'next/server';
import { prisma } from '../../../../lib/prisma';
export async function GET(req: Request) {
const url = new URL(req.url);
const slug = url.searchParams.get('slug')?.trim().toLowerCase();
if (!slug) {
return NextResponse.json({ error: 'Missing slug' }, { status: 400 });
}
const existing = await prisma.listingTranslation.findFirst({
where: { slug, listing: { removedAt: null } },
select: { id: true },
});
return NextResponse.json({ available: !existing });
}