feat: created getProductById feature in actions library

This commit is contained in:
Leon Xu committed 2023-12-30 14:12:12 -08:00
1 parent f8991b8709
commit 39fdf4c88d
1 file changed
+14
+14
View File
@@ -45,4 +45,18 @@ export async function scrapeAndStoreProduct(productUrl: string) {
} catch (error: any) {
throw new Error(`Failed to create/update product; ${error.message}`)
}
}
export async function getProductById(productId: string) {
try {
connectToDB();
const product = await Product.findOne({ _id: productId });
if (!product) return null;
return product
} catch (error) {
console.log(error);
}
}