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

@@ -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 };