diff --git a/lib/actions/index.ts b/lib/actions/index.ts index 21390d1..56a422d 100644 --- a/lib/actions/index.ts +++ b/lib/actions/index.ts @@ -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); + } } \ No newline at end of file