update prisma search products,

This commit is contained in:
louiscklaw
2025-06-15 12:42:08 +08:00
parent 1216bef8f8
commit d82afe5a5f
3 changed files with 20 additions and 12 deletions

View File

@@ -3,11 +3,11 @@ import type { NextRequest } from 'next/server';
import { logger } from 'src/utils/logger';
import { STATUS, response, handleError } from 'src/utils/response';
import { _products } from 'src/_mock/_product';
import { getProductBySkuOrName } from 'src/app/services/product.service';
// ----------------------------------------------------------------------
export const runtime = 'edge';
// export const runtime = 'edge';
/** **************************************
* GET - Search products
@@ -21,14 +21,11 @@ export async function GET(req: NextRequest) {
return response({ results: [] }, STATUS.OK);
}
const products = _products();
const testResult = await getProductBySkuOrName(query);
// Accept search by name or sku
const results = products.filter(({ name, sku }) => name.toLowerCase().includes(query) || sku?.toLowerCase().includes(query));
logger('[Product] search-results', testResult?.length);
logger('[Product] search-results', results.length);
return response({ results }, STATUS.OK);
return response({ testResult }, STATUS.OK);
} catch (error) {
return handleError('Product - Get search', error);
}

View File

@@ -0,0 +1,5 @@
###
GET http://localhost:7272/api/product/search?query=B
###
GET http://localhost:7272/api/product/search?query=Classic