From e54bbb5c5c3204bb72c39d8ed56ecac66a817d00 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 21 Sep 2021 13:06:09 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9A=20Added=20an=20endpoint=20for=20fe?= =?UTF-8?q?tching=20volume=20metadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moleculer.config.ts | 2 +- services/comicvine.service.ts | 46 ++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/moleculer.config.ts b/moleculer.config.ts index 89af652..a6b7fdb 100644 --- a/moleculer.config.ts +++ b/moleculer.config.ts @@ -64,7 +64,7 @@ const brokerConfig: BrokerOptions = { // More info: https://moleculer.services/docs/0.14/networking.html // Note: During the development, you don't need to define it because all services will be loaded locally. // In production you can set it via `TRANSPORTER=nats://localhost:4222` environment variable. - transporter: null, // "NATS" + transporter: "NATS", // "NATS" // Define a cacher. // More info: https://moleculer.services/docs/0.14/caching.html diff --git a/services/comicvine.service.ts b/services/comicvine.service.ts index 8d2d084..d2a2024 100644 --- a/services/comicvine.service.ts +++ b/services/comicvine.service.ts @@ -12,7 +12,7 @@ export default class ComicVineService extends Service { this.parseServiceSchema({ name: "comicvine", actions: { - fetchSeries: { + fetchResource: { rest: "/fetchresource", params: { format: { type: "string", optional: false }, @@ -48,12 +48,13 @@ export default class ComicVineService extends Service { "?api_key=" + CV_API_KEY, params: ctx.params, - transformResponse: r => { + transformResponse: (r) => { const matches = JSON.parse(r); return matchScorer( matches.results, ctx.params.scorerConfiguration.searchQuery, - ctx.params.scorerConfiguration.rawFileDetails + ctx.params.scorerConfiguration + .rawFileDetails ); }, headers: { Accept: "application/json" }, @@ -65,15 +66,17 @@ export default class ComicVineService extends Service { search: { rest: "/search", params: {}, - handler: async (ctx: Context<{ - format: string; - sort: string; - query: string; - fieldList: string; - limit: string; - offset: string; - resources: string; - }>) => { + handler: async ( + ctx: Context<{ + format: string; + sort: string; + query: string; + fieldList: string; + limit: string; + offset: string; + resources: string; + }> + ) => { const response = await axios.request({ url: CV_BASE_URL + @@ -87,6 +90,25 @@ export default class ComicVineService extends Service { return data; }, }, + getVolumes: { + rest: "POST /getVolumes", + params: {}, + handler: async ( + ctx: Context<{ + volumeURI: string; + data: {}; + }> + ) => { + const response = await axios.request({ + url: + ctx.params.volumeURI + "?api_key=" + CV_API_KEY, + params: ctx.params.data, + headers: { Accept: "application/json" }, + }); + const { data } = response; + return data; + }, + }, }, }); }