Compare commits

...

4 Commits

Author SHA1 Message Date
louiscklaw
e791b01160 update, 2025-06-15 12:56:29 +08:00
louiscklaw
8383be13bc update, 2025-06-15 12:44:58 +08:00
louiscklaw
d82afe5a5f update prisma search products, 2025-06-15 12:42:08 +08:00
louiscklaw
1216bef8f8 "update tsconfig patterns and compiler options across all projects" 2025-06-15 12:08:17 +08:00
10 changed files with 65 additions and 50 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,12 +21,9 @@ export async function GET(req: NextRequest) {
return response({ results: [] }, STATUS.OK);
}
const products = _products();
const results = 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', results.length);
logger('[Product] search-results', results?.length);
return response({ results }, STATUS.OK);
} catch (error) {

View File

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

View File

@@ -68,9 +68,7 @@ type UpdateProduct = {
async function listProducts(): Promise<ProductItem[]> {
return prisma.productItem.findMany({
include: {
reviews: true,
},
include: { reviews: true },
});
}
@@ -82,6 +80,14 @@ async function getProduct(productId: string): Promise<ProductItem | null> {
});
}
async function getProductBySkuOrName(searchText: string): Promise<ProductItem[] | null> {
return prisma.productItem.findMany({
where: { OR: [{ sku: { contains: searchText, mode: 'insensitive' } }, { name: { contains: searchText, mode: 'insensitive' } }] },
include: { reviews: true },
//
});
}
async function createProduct(productData: any) {
return await prisma.productItem.create({ data: productData });
}
@@ -97,4 +103,4 @@ async function deleteProduct(productId: string) {
return prisma.productItem.delete({ where: { id: productId } });
}
export { getProduct, listProducts, createProduct, updateProduct, deleteProduct, type CreateProduct, type UpdateProduct };
export { getProduct, listProducts, createProduct, updateProduct, deleteProduct, getProductBySkuOrName, type CreateProduct, type UpdateProduct };

View File

@@ -34,9 +34,8 @@
"node_modules",
".next",
//
"**/* copy *.tsx",
"**/* copy.tsx",
"**/*.bak",
"**/* copy *.*",
"**/* copy.*",
"**/*.bak",
"**/*.bug",
"**/*.del",

View File

@@ -99,7 +99,9 @@ export async function createProduct(productData: IProductItem) {
* Work on server
*/
const data = { productData };
await axiosInstance.post(endpoints.product.create, data);
const {
data: { id },
} = await axiosInstance.post(endpoints.product.create, data);
/**
* Work in local
@@ -109,7 +111,7 @@ export async function createProduct(productData: IProductItem) {
(currentData: any) => {
const currentProducts: IProductItem[] = currentData?.products;
const products = [...currentProducts, productData];
const products = [...currentProducts, { ...productData, id }];
return { ...currentData, products };
},

View File

@@ -17,13 +17,15 @@ export function ProductList({ products, loading, sx, ...other }: Props) {
const renderLoading = () => <ProductItemSkeleton />;
const renderList = () =>
products.map((product) => (
products.map((product) => {
return (
<ProductItem
key={product.id}
product={product}
detailsHref={paths.product.details(product.id)}
/>
));
);
});
return (
<>

View File

@@ -1,39 +1,35 @@
{
"compilerOptions": {
"allowJs": true,
/* Bundler */
"baseUrl": ".",
"module": "ESNext",
"esModuleInterop": true,
"incremental": true,
"isolatedModules": true,
"jsx": "react-jsx",
"allowJs": true,
"resolveJsonModule": true,
/* Build */
"target": "ES2020",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"module": "ESNext",
"moduleResolution": "bundler",
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"incremental": true,
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"esModuleInterop": true,
"isolatedModules": true,
/* Linting */
"strict": true,
"noEmit": true,
"strictNullChecks": true
"strictNullChecks": true,
/* Build */
"target": "ES2020",
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo"
},
"include": [
"src"
],
"exclude": [
"node_modules",
".next",
//
"**/* copy *.tsx",
"**/* copy.tsx",
"**/*.bak",
"**/* copy *.*",
"**/* copy.*",
"**/*.bak",
"**/*.bug",
"**/*.del",
@@ -42,9 +38,12 @@
"**/*.tmp",
"**/*del"
],
"include": [
"src"
],
"references": [
{
"path": "./tsconfig.node.json"
}
],
]
}

View File

@@ -6,8 +6,8 @@
"allowSyntheticDefaultImports": true
},
"exclude": [
"**/* copy *.tsx",
"**/* copy.tsx",
"**/* copy *.*",
"**/* copy.*",
"**/*.bak",
"**/*.bak",
"**/*.bug",
@@ -16,5 +16,8 @@
"**/*.log",
"**/*.tmp",
"**/*del"
], "include": ["vite.config.ts"]
],
"include": [
"vite.config.ts"
]
}

View File

@@ -24,9 +24,8 @@
"node_modules",
".next",
//
"**/* copy *.tsx",
"**/* copy.tsx",
"**/*.bak",
"**/* copy *.*",
"**/* copy.*",
"**/*.bak",
"**/*.bug",
"**/*.del",

View File

@@ -1,9 +1,9 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
"moduleResolution": "Node"
},
"exclude": [
"**/* copy *.tsx",