This repository has been archived on 2026-07-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
aniwatch-api/src/controllers/animeSearchSuggestion.controller.ts
T
2023-11-22 13:55:59 +05:30

32 lines
893 B
TypeScript

import createHttpError from "http-errors";
import { type RequestHandler } from "express";
import { scrapeAnimeSearchSuggestion } from "../parsers/index.js";
import { type AnimeSearchSuggestQueryParams } from "../models/controllers/index.js";
// /anime/search/suggest?q=${query}
const getAnimeSearchSuggestion: RequestHandler<
unknown,
Awaited<ReturnType<typeof scrapeAnimeSearchSuggestion>>,
unknown,
AnimeSearchSuggestQueryParams
> = async (req, res, next) => {
try {
const query: string | null = req.query.q
? decodeURIComponent(req.query.q as string)
: null;
if (query === null) {
throw createHttpError.BadRequest("Search keyword required");
}
const data = await scrapeAnimeSearchSuggestion(query);
res.status(200).json(data);
} catch (err: any) {
console.error(err);
next(err);
}
};
export default getAnimeSearchSuggestion;