feat: created getProductById feature in actions library
This commit is contained in:
1 parent
f8991b8709
commit
39fdf4c88d
1 file changed
+14
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user