Skip to content

Commit

Permalink
feat: added anime category controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshRitesh12 committed Aug 2, 2023
1 parent 92dfaad commit 59c7c23
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/controllers/animeCategory.controller.ts
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;

0 comments on commit 59c7c23

Please sign in to comment.