-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added anime category controller
- Loading branch information
1 parent
92dfaad
commit 59c7c23
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |