feat: implement business detail client view with interactive features including rating, favoriting, messaging, and analytics tracking
This commit is contained in:
@@ -8,6 +8,7 @@ export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const category = searchParams.get('category')
|
||||
const q = searchParams.get('q')?.toLowerCase()
|
||||
const location = searchParams.get('location')?.toLowerCase()
|
||||
const featured = searchParams.get('featured')
|
||||
const countryId = searchParams.get('countryId')
|
||||
|
||||
@@ -19,11 +20,12 @@ export async function GET(request: NextRequest) {
|
||||
isSuspended: false
|
||||
}
|
||||
}
|
||||
|
||||
// Build the conditions array
|
||||
const conditions: any[] = [];
|
||||
|
||||
if (category && category !== 'All') {
|
||||
// Robust check: IDs are usually alphanumeric and long, without spaces or special chars
|
||||
// Names like "Agriculture & Agrobusiness" have spaces or special chars.
|
||||
const isId = /^[a-z0-9-]+$/.test(category) && category.length > 20;
|
||||
|
||||
if (isId) {
|
||||
where.categoryId = category
|
||||
} else {
|
||||
@@ -32,13 +34,30 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
if (featured === 'true') where.isFeatured = true
|
||||
if (countryId) where.countryId = countryId
|
||||
|
||||
if (q) {
|
||||
where.OR = [
|
||||
{ name: { contains: q, mode: 'insensitive' } },
|
||||
{ description: { contains: q, mode: 'insensitive' } },
|
||||
// Simplified tags check
|
||||
{ tags: { has: q } }
|
||||
]
|
||||
conditions.push({
|
||||
OR: [
|
||||
{ name: { contains: q, mode: 'insensitive' } },
|
||||
{ description: { contains: q, mode: 'insensitive' } },
|
||||
{ city: { contains: q, mode: 'insensitive' } },
|
||||
{ location: { contains: q, mode: 'insensitive' } },
|
||||
{ tags: { has: q } }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
if (location) {
|
||||
conditions.push({
|
||||
OR: [
|
||||
{ city: { contains: location, mode: 'insensitive' } },
|
||||
{ location: { contains: location, mode: 'insensitive' } }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
where.AND = conditions;
|
||||
}
|
||||
|
||||
const dbBusinesses = await prisma.business.findMany({
|
||||
|
||||
Reference in New Issue
Block a user