diff --git a/pages/api/fetchProducts.ts b/pages/api/fetchProducts.ts index 42ee41f..e3ab5d0 100644 --- a/pages/api/fetchProducts.ts +++ b/pages/api/fetchProducts.ts @@ -1,8 +1,8 @@ /* eslint-disable import/no-anonymous-default-export */ import groq from "groq"; +import { NextApiRequest, NextApiResponse } from "next"; import client from "../../client"; -import { NextApiRequest, NextApiResponse } from 'next'; -import { productsNameFilter } from '../../utils/productsReducer' +import { productsNameFilter } from "../../utils/productsReducer"; const query = groq`*[_type == "product" && slug.current == $slug][0]{ title, @@ -24,14 +24,17 @@ const query = groq`*[_type == "product" && slug.current == $slug][0]{ }`; export default async (req: NextApiRequest, res: NextApiResponse) => { - try { - console.log(req.body) - const fetchAllProducts = req.body.map(async (item: any) => await client.fetch(query, { slug: productsNameFilter(item.title) })); - const products = await Promise.all(fetchAllProducts) - res.json(products) + console.log(req.body); + const fetchAllProducts = req.body.map( + async (item: any) => + await client.fetch(query, { slug: productsNameFilter(item.title) }) + ); + const products = await Promise.all(fetchAllProducts); + console.log(products); + res.json(products); } catch (error) { - console.log(error) - res.status(500).json({ error: error, errorText: 'Fetch Products Failed' }) + console.log(error); + res.status(500).json({ error: error, errorText: "Fetch Products Failed" }); } -} \ No newline at end of file +};