From 84a79810c358dece1b3bd2b013a2d788ec100f44 Mon Sep 17 00:00:00 2001 From: Ritesh Ghosh Date: Mon, 7 Aug 2023 14:58:25 +0530 Subject: feat(controllerTypes): added request handler types --- src/controllers/animeSearch.controller.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/controllers/animeSearch.controller.ts') diff --git a/src/controllers/animeSearch.controller.ts b/src/controllers/animeSearch.controller.ts index b0990c3..f03c40b 100644 --- a/src/controllers/animeSearch.controller.ts +++ b/src/controllers/animeSearch.controller.ts @@ -1,31 +1,32 @@ -import { scrapeAnimeSearch } from "../parsers"; import createHttpError from "http-errors"; -import { AnimeCategories } from "../models"; -import { Request, Response, NextFunction, Handler } from "express"; +import { RequestHandler } from "express"; +import { scrapeAnimeSearch } from "../parsers"; +import { AnimeSearchQueryParams } from "../models/controllers"; // /anime/search?q=${query}&page=${page} -const getAnimeSearch: Handler = async ( - req: Request, - res: Response, - next: NextFunction -) => { +const getAnimeSearch: RequestHandler< + unknown, + Awaited>, + unknown, + AnimeSearchQueryParams +> = async (req, res, next) => { try { - const q: string | null = req.query.q + const query: string | null = req.query.q ? decodeURIComponent(req.query.q as string) : null; const page: number = req.query.page ? Number(decodeURIComponent(req.query?.page as string)) : 1; - if (q === null) { + if (query === null) { throw createHttpError.BadGateway("Search keyword required"); } - const data = await scrapeAnimeSearch(q, page); + const data = await scrapeAnimeSearch(query, page); res.status(200).json(data); } catch (err: any) { - // console.error(err); + console.error(err); next(err); } }; -- cgit v1.2.3