diff options
| author | Ritesh Ghosh <[email protected]> | 2023-08-02 13:45:49 +0530 |
|---|---|---|
| committer | Ritesh Ghosh <[email protected]> | 2023-08-02 13:45:49 +0530 |
| commit | 59c7c23f09ea3303999385f95f2bd488bfb07ca8 (patch) | |
| tree | aae8a871746f4153cdfc984d57615b9900bc65e1 | |
| parent | 92dfaad3c624da881800832b5ad3b95ce801bd0a (diff) | |
| download | aniwatch-api-59c7c23f09ea3303999385f95f2bd488bfb07ca8.tar.xz aniwatch-api-59c7c23f09ea3303999385f95f2bd488bfb07ca8.zip | |
feat: added anime category controller
| -rw-r--r-- | src/controllers/animeCategory.controller.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/controllers/animeCategory.controller.ts b/src/controllers/animeCategory.controller.ts new file mode 100644 index 0000000..ba44127 --- /dev/null +++ b/src/controllers/animeCategory.controller.ts @@ -0,0 +1,32 @@ +import { scrapeAnimeCategory } from "../parsers"; +import createHttpError from "http-errors"; +import { AnimeCategories } from "../models"; +import { Request, Response, NextFunction, Handler } from "express"; + +// /anime/:category?page=${page} +const getAnimeCategory: Handler = async ( + req: Request, + res: Response, + next: NextFunction +) => { + try { + const category: AnimeCategories = decodeURIComponent( + req.params.category + ) as AnimeCategories; + + const page: number = req.query.page + ? Number(decodeURIComponent(req.query?.page as string)) + : 1; + + if (!category) throw createHttpError.BadRequest("category required"); + + const data = await scrapeAnimeCategory(category, page); + + res.status(200).json(data); + } catch (err: any) { + // console.error(err); + next(err); + } +}; + +export default getAnimeCategory; |
