From 8be7440a64e0fc3964f5d9a76151fa682f005df3 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 4 Apr 2022 13:28:24 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Tweaking=20the=20CV=20api=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/comicvine.service.ts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/services/comicvine.service.ts b/services/comicvine.service.ts index 91126e0..c5884c3 100644 --- a/services/comicvine.service.ts +++ b/services/comicvine.service.ts @@ -197,6 +197,10 @@ export default class ComicVineService extends Service { ctx.params.scorerConfiguration.searchParams ); const results: any = []; + console.log( + "passed to fetchvolumesfromcv", + ctx.params + ); const volumes = await this.fetchVolumesFromCV( ctx.params, results @@ -300,15 +304,22 @@ export default class ComicVineService extends Service { }, }, methods: { - fetchVolumesFromCV: async (params, output: any[] = []) => { - let currentPage = parseInt(params.page, 10); + fetchVolumesFromCV: async (payload, output: any[] = []) => { + const { format, query, limit, page, resources } = payload; + let currentPage = parseInt(page, 10); const response = await axios.request({ url: CV_BASE_URL + "search" + "?api_key=" + process.env.COMICVINE_API_KEY, - params, + params: { + format, + query, + limit, + page, + resources, + }, headers: { "Accept": "application/json", "User-Agent": "ThreeTwo", @@ -319,7 +330,7 @@ export default class ComicVineService extends Service { // 1. Calculate total pages const totalPages = Math.floor( parseInt(data.number_of_total_results, 10) / - parseInt(params.limit, 10) + parseInt(limit, 10) ); // 1a. If total results are <= 100, just return the results if (parseInt(data.number_of_total_results, 10) <= 100) { @@ -329,13 +340,22 @@ export default class ComicVineService extends Service { if (currentPage <= totalPages) { output.push(...data.results); currentPage += 1; - params.page = currentPage; + // Params.page = currentPage; console.log( `Fetching results for page ${currentPage} (of ${ totalPages + 1 })...` ); - return await this.fetchVolumesFromCV(params, output); + return await this.fetchVolumesFromCV( + { + format, + query, + limit, + page: currentPage, + resources, + }, + output + ); } else { return [...output]; }