import { NextRequest, NextResponse } from 'next/server' import { prisma } from '@/libs/prisma' export async function GET(request: NextRequest) { try { const searchParams = request.nextUrl.searchParams const category = searchParams.get('category') const keyword = searchParams.get('keyword') let whereCondition: any = {} if (category) { whereCondition['roof_material'] = category } if (keyword) { whereCondition['product_name'] = { contains: keyword, } } console.log('๐Ÿš€ ~ /api/suitable/list: ~ prisma where condition:', whereCondition) // @ts-ignore const suitables = await prisma.MS_SUITABLE.findMany({ where: whereCondition, orderBy: { product_name: 'asc', }, }) return NextResponse.json(suitables) } catch (error) { console.error('โŒ ๋ฐ์ดํ„ฐ ์กฐํšŒ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค:', error) return NextResponse.json({ error: '๋ฐ์ดํ„ฐ ์กฐํšŒ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค' }, { status: 500 }) } }