update prisma search products,
This commit is contained in:
@@ -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 };
|
||||
|
Reference in New Issue
Block a user