I have this function, I created it but then I'm getting confused and don't know how to return the data.
I have tried Promise.all() before but it's seems I do not quite understand it so I have removed it from my code, I don't know if it's a correct way to do it or not.
CodePudding user response:
In async...await, async expects an await to follow. In your model you are declaring the function as async but inside you have promise. Easiest solution is to use await instead of promise.
static async getAnilist(title) {
const Anilist = new anilist()
const titleToId = await Anilist.searchEntry.anime(title, null, 1, 1);
const animeID = titleToID.media[0].id;
const data = await Anilist.media.anime(animeID);
const detailInfo = {
AnimeID: animeID,
Schedule: data.airingSchedule[0],
Score: data.averageScore,
BannerImg: data.bannerImage,
Character: data.characters,
Country: data.countryOfOrigin,
CoverImg: data.coverImage,
Duration: data.duration,
EndData: data.endDate,
EpisodeTotal: data.episodes,
Genre: data.genres,
Season: data.season,
SeasonYear: data.seasonYear,
Status: data.status,
Studio: data.studios,
UpdateAt: data.updatedAt,
};
const animeInfo = detailInfo;
return animeInfo;
}
NB: You can optimize the above to be more consise. I translated it as-is.

