diff options
| author | Ritesh Ghosh <[email protected]> | 2023-12-17 19:45:22 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-12-17 19:45:22 +0530 |
| commit | 948183d279e0a020a10011f99e9e5fbb7c8b3ef8 (patch) | |
| tree | 29c3db39ad6778fdd8a676d0ae97ffe656df9bef /src/controllers | |
| parent | 750386f04c5aec410ae54b1f2d0119271842c4da (diff) | |
| parent | 8826dd276fe4a5ccab2b074d77191b81b265e528 (diff) | |
| download | aniwatch-api-948183d279e0a020a10011f99e9e5fbb7c8b3ef8.tar.xz aniwatch-api-948183d279e0a020a10011f99e9e5fbb7c8b3ef8.zip | |
Merge pull request #13 from ghoshRitesh12/est-schedule
Add Estimated Schedule feature
Diffstat (limited to 'src/controllers')
| -rw-r--r-- | src/controllers/estimatedSchedule.controller.ts | 36 | ||||
| -rw-r--r-- | src/controllers/index.ts | 2 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/controllers/estimatedSchedule.controller.ts b/src/controllers/estimatedSchedule.controller.ts new file mode 100644 index 0000000..bead83e --- /dev/null +++ b/src/controllers/estimatedSchedule.controller.ts @@ -0,0 +1,36 @@ +import createHttpError from "http-errors"; +import { type RequestHandler } from "express"; +import { scrapeEstimatedSchedule } from "../parsers/index.js"; +import { type EstimatedScheduleQueryParams } from "../models/controllers/index.js"; + +// /anime/schedule?date=${date} +const getEstimatedSchedule: RequestHandler< + unknown, + Awaited<ReturnType<typeof scrapeEstimatedSchedule>>, + unknown, + EstimatedScheduleQueryParams +> = async (req, res, next) => { + try { + const dateQuery = req.query.date + ? decodeURIComponent(req.query.date as string) + : null; + + if (dateQuery === null) { + throw createHttpError.BadRequest("Date payload required"); + } + if (!/^\d{4}-\d{2}-\d{2}$/.test(dateQuery)) { + throw createHttpError.BadRequest( + "Invalid date payload format. Months and days must have 2 digits" + ); + } + + const data = await scrapeEstimatedSchedule(dateQuery); + + res.status(200).json(data); + } catch (err: any) { + console.error(err); + next(err); + } +}; + +export default getEstimatedSchedule; diff --git a/src/controllers/index.ts b/src/controllers/index.ts index 21f9d10..6e90440 100644 --- a/src/controllers/index.ts +++ b/src/controllers/index.ts @@ -6,6 +6,7 @@ import getAnimeCategory from "./animeCategory.controller.js"; import getProducerAnimes from "./animeProducer.controller.js"; import getEpisodeServers from "./episodeServers.controller.js"; import getAnimeAboutInfo from "./animeAboutInfo.controller.js"; +import getEstimatedSchedule from "./estimatedSchedule.controller.js"; import getAnimeEpisodeSources from "./animeEpisodeSrcs.controller.js"; import getAnimeSearchSuggestion from "./animeSearchSuggestion.controller.js"; @@ -18,6 +19,7 @@ export { getEpisodeServers, getProducerAnimes, getAnimeAboutInfo, + getEstimatedSchedule, getAnimeEpisodeSources, getAnimeSearchSuggestion, }; |
