24 lines
657 B
TypeScript
24 lines
657 B
TypeScript
import { db } from "@/db";
|
|
import { bb_products } from "@/db/schema";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const allProducts = await db.select().from(bb_products).limit(50);
|
|
const mapped = allProducts.map((item: any) => ({
|
|
id: item.uuid,
|
|
name: item.productName,
|
|
slug: slugify(item.productName),
|
|
...item
|
|
}));
|
|
return Response.json({ success: true, data: mapped });
|
|
} catch (error) {
|
|
return Response.json({ success: false, error: String(error) }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
function slugify(name: string): string {
|
|
return name
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/(^-|-$)+/g, '');
|
|
}
|