From f5d944e9063bd6582544d9d448934a6f16897eca Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 4 Apr 2024 06:28:52 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9A=20Added=20a=20getStoryArc=20endpoi?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/comicvine.service.ts | 36 ++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/services/comicvine.service.ts b/services/comicvine.service.ts index ef5ae66..ef4b07d 100644 --- a/services/comicvine.service.ts +++ b/services/comicvine.service.ts @@ -3,7 +3,7 @@ import { Service, ServiceBroker, Context } from "moleculer"; import axios from "axios"; import delay from "delay"; -import { isNil, isUndefined } from "lodash"; +import { isNil } from "lodash"; import { fetchReleases, FilterTypes, SortTypes } from "comicgeeks"; import { matchScorer, rankVolumes } from "../utils/searchmatchscorer.utils"; import { @@ -72,14 +72,14 @@ export default class ComicVineService extends Service { }, getIssuesForSeries: { rest: "POST /getIssuesForSeries", - params: {}, handler: async ( - ctx: Context<{ comicObjectID: string }> + ctx: Context<{ comicObjectId: string }> ) => { + const { comicObjectId } = ctx.params; // 1. Query mongo to get the comic document by its _id const comicBookDetails: any = await this.broker.call( "library.getComicBookById", - { id: ctx.params.comicObjectID } + { id: comicObjectId } ); // 2. Query CV and get metadata for them const issues = await axios({ @@ -161,6 +161,32 @@ export default class ComicVineService extends Service { return { result: paginatedData, meta: paginationInfo }; }, }, + getStoryArcs: { + rest: "POST /getStoryArcs", + handler: async (ctx: Context<{ comicObject: any }>) => { + const { comicObject } = ctx.params; + console.log(JSON.stringify(comicObject, null, 2)); + // 2. Query CV and get metadata for them + const storyArcs = await axios({ + url: + CV_BASE_URL + + "story_arcs" + + "?api_key=" + + process.env.COMICVINE_API_KEY, + params: { + resources: "story_arcs", + limit: "100", + format: "json", + filter: `volume:${comicObject.sourcedMetadata.comicvine.volumeInformation.id}`, + }, + headers: { + Accept: "application/json", + "User-Agent": "ThreeTwo", + }, + }); + return storyArcs.data; + }, + }, volumeBasedSearch: { rest: "POST /volumeBasedSearch", params: {}, @@ -223,7 +249,7 @@ export default class ComicVineService extends Service { } ); - // 2b. cover_date:2014-01-01|2016-12-31 for the issue year 2015 + // 2b. E.g.: cover_date:2014-01-01|2016-12-31 for the issue year 2015 let coverDateFilter = ""; if ( !isNil(