build ok,
This commit is contained in:
@@ -47,9 +47,7 @@ export async function GET(req: NextRequest) {
|
||||
products: paginatedProducts,
|
||||
totalPages,
|
||||
totalItems,
|
||||
categoryOptions: Array.from(
|
||||
new Set(_products.map(({ category: c_category }) => c_category))
|
||||
), // Remove duplicate categories
|
||||
categoryOptions: Array.from(new Set(_products.map(({ category: c_category }) => c_category))), // Remove duplicate categories
|
||||
},
|
||||
STATUS.OK
|
||||
);
|
||||
@@ -70,9 +68,7 @@ function paginateProducts(products: Products, page: number, perPage: number) {
|
||||
function filterProducts(products: Products, searchQuery: string, category: string) {
|
||||
return products.filter(({ id, name, category: prodCategory }) => {
|
||||
// Accept search by id or name
|
||||
const matchesSearch = searchQuery
|
||||
? id.includes(searchQuery) || name.toLowerCase().includes(searchQuery)
|
||||
: true;
|
||||
const matchesSearch = searchQuery ? id.includes(searchQuery) || name.toLowerCase().includes(searchQuery) : true;
|
||||
const matchesCategory = category ? prodCategory === category : true;
|
||||
|
||||
return matchesSearch && matchesCategory;
|
||||
|
Reference in New Issue
Block a user