feat: added mostPopular, mostFavorite and latestCompleted to the home route response

This commit is contained in:
WBRK-dev
2024-07-21 10:18:05 +02:00
parent 62fa83a56d
commit 5d929461ce
5 changed files with 56 additions and 2 deletions
+39 -2
View File
@@ -182,9 +182,7 @@ console.log(data);
id: string,
name: string,
poster: string,
duration: string,
type: string,
rating: string,
episodes: {
sub: number,
dub: number,
@@ -258,6 +256,45 @@ console.log(data);
},
{...},
],
mostPopularAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
mostFavoriteAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
latestCompletedAnimes: [
{
id: string,
name: string,
poster: string,
type: string,
episodes: {
sub: number,
dub: number,
}
},
{...},
],
}
```
+6
View File
@@ -25,6 +25,9 @@ async function scrapeHomePage(): Promise<ScrapedHomePage | HttpError> {
month: [],
},
topAiringAnimes: [],
mostPopularAnimes: [],
mostFavoriteAnimes: [],
latestCompletedAnimes: [],
genres: [],
};
@@ -160,6 +163,9 @@ async function scrapeHomePage(): Promise<ScrapedHomePage | HttpError> {
});
res.topAiringAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(1) .anif-block-ul ul li");
res.mostPopularAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(2) .anif-block-ul ul li");
res.mostFavoriteAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(3) .anif-block-ul ul li");
res.latestCompletedAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(4) .anif-block-ul ul li");
return res;
} catch (err: any) {
+2
View File
@@ -39,6 +39,8 @@ export interface LatestEpisodeAnime extends Anime {}
export interface TopUpcomingAnime extends Anime {}
export interface TopAiringAnime extends MostPopularAnime {}
export interface MostFavoriteAnime extends MostPopularAnime {}
export interface LatestCompletedAnime extends MostPopularAnime {}
export interface AnimeGeneralAboutInfo
extends Pick<Anime, CommonAnimeProps>,
+6
View File
@@ -4,6 +4,9 @@ import type {
TopAiringAnime,
TopUpcomingAnime,
LatestEpisodeAnime,
MostFavoriteAnime,
MostPopularAnime,
LatestCompletedAnime,
} from "../anime.js";
import type { HttpError } from "http-errors";
import type { ScrapedAnimeCategory } from "./animeCategory.js";
@@ -15,4 +18,7 @@ export interface ScrapedHomePage
latestEpisodeAnimes: Array<LatestEpisodeAnime> | HttpError;
topUpcomingAnimes: Array<TopUpcomingAnime> | HttpError;
topAiringAnimes: Array<TopAiringAnime> | HttpError;
mostPopularAnimes: Array<MostPopularAnime> | HttpError;
mostFavoriteAnimes: Array<MostFavoriteAnime> | HttpError;
latestCompletedAnimes: Array<LatestCompletedAnime> | HttpError;
}
+3
View File
@@ -9,6 +9,9 @@ test("returns anime information present in homepage", async () => {
expect(data.latestEpisodeAnimes).not.toEqual([]);
expect(data.topUpcomingAnimes).not.toEqual([]);
expect(data.topAiringAnimes).not.toEqual([]);
expect(data.mostPopularAnimes).not.toEqual([]);
expect(data.mostFavoriteAnimes).not.toEqual([]);
expect(data.latestCompletedAnimes).not.toEqual([]);
expect(data.genres).not.toEqual([]);
expect(data.top10Animes.today).not.toEqual([]);