aboutsummaryrefslogtreecommitdiff
path: root/src/controllers/animeSearch.controller.ts
diff options
context:
space:
mode:
authorRitesh Ghosh <[email protected]>2023-08-07 14:58:25 +0530
committerRitesh Ghosh <[email protected]>2023-08-07 14:58:25 +0530
commit84a79810c358dece1b3bd2b013a2d788ec100f44 (patch)
treed6c52e37abc4a76a7da2e32a7ae7622ad22f11bd /src/controllers/animeSearch.controller.ts
parent205619be557a7e1ac6152f370f440005feea0050 (diff)
downloadaniwatch-api-84a79810c358dece1b3bd2b013a2d788ec100f44.tar.xz
aniwatch-api-84a79810c358dece1b3bd2b013a2d788ec100f44.zip
feat(controllerTypes): added request handler types
Diffstat (limited to 'src/controllers/animeSearch.controller.ts')
-rw-r--r--src/controllers/animeSearch.controller.ts25
1 files changed, 13 insertions, 12 deletions
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<ReturnType<typeof scrapeAnimeSearch>>,
+ 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);
}
};