From efd2fbbe267716e8e98a8789a841c12b93976add Mon Sep 17 00:00:00 2001 From: pheralb Date: Sun, 26 Jun 2022 18:42:46 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=92=EF=B8=8F=20Add=20.json=20to=20the=20i?= =?UTF-8?q?mport.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/api/all.ts | 2 +- src/pages/api/categories.ts | 2 +- src/pages/api/search.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/api/all.ts b/src/pages/api/all.ts index 1ca35f0..8f57395 100644 --- a/src/pages/api/all.ts +++ b/src/pages/api/all.ts @@ -1,4 +1,4 @@ -import db from "data/svgs"; +import db from "data/svgs.json"; import type { NextApiRequest, NextApiResponse } from "next"; import { SvgData } from "@/interfaces/svgData"; diff --git a/src/pages/api/categories.ts b/src/pages/api/categories.ts index 925580f..f108a1c 100644 --- a/src/pages/api/categories.ts +++ b/src/pages/api/categories.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import db from "data/svgs"; +import db from "data/svgs.json"; export default function handler(req: NextApiRequest, res: NextApiResponse) { // Get unique categories: diff --git a/src/pages/api/search.ts b/src/pages/api/search.ts index 5c7383c..b9a8401 100644 --- a/src/pages/api/search.ts +++ b/src/pages/api/search.ts @@ -1,4 +1,4 @@ -import db from "data/svgs"; +import db from "data/svgs.json"; import { NextApiRequest, NextApiResponse } from "next"; export default function handler(req: NextApiRequest, res: NextApiResponse) { @@ -14,7 +14,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { if (q) { const results = db.filter((product) => { const { title } = product; - return title; + return title.toLowerCase().includes(q.toString()); }); return res.status(200).json(results); } @@ -23,11 +23,11 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { if (c) { const results = db.filter((product) => { const { category } = product; - return category; + return category.toLowerCase().includes(q.toString()); }); return res.status(200).json(results); } // ✖ Error -> - res.status(400).json({ info: "Error: api query not found." }); + res.status(400).json({ info: "[/api/search] Error: api query not found." }); }