feat: added getSimilarProducts

This commit is contained in:
Leon Xu committed 2023-12-30 15:59:33 -08:00
1 parent 155fb60ec3
commit e29d28ac18
1 file changed
+16
+16
View File
@@ -71,4 +71,20 @@ export async function getAllProducts() {
} catch (error) {
console.log(error);
}
}
export async function getSimilarProducts(productId: string) {
try {
connectToDB();
const currentProduct = await Product.findById(productId);
if (!currentProduct) return null;
const similarProducts = await Product.find({ _id: { $ne: productId } }).limit(3);
return similarProducts
} catch (error) {
console.log(error);
}
}