async function searchProducts(filters: {
category?: string;
minPrice?: number;
maxPrice?: number;
inStock?: boolean;
query?: string;
}) {
let query = puri.table("products")
.select({
id: "products.id",
name: "products.name",
price: "products.price",
stock: "products.stock"
});
// ์กฐ๊ฑด๋ถ ํํฐ๋ง
if (filters.category) {
query = query.where("products.category", filters.category);
}
if (filters.minPrice !== undefined) {
query = query.where("products.price", ">=", filters.minPrice);
}
if (filters.maxPrice !== undefined) {
query = query.where("products.price", "<=", filters.maxPrice);
}
if (filters.inStock) {
query = query.where("products.stock", ">", 0);
}
if (filters.query) {
query = query.where("products.name", "like", `%${filters.query}%`);
}
return query
.orderBy("products.created_at", "desc")
.limit(50);
}