diff --git a/moleculer.config.ts b/moleculer.config.ts index 3476ed3..646534c 100644 --- a/moleculer.config.ts +++ b/moleculer.config.ts @@ -76,7 +76,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/api.service.ts b/services/api.service.ts index ee1ab7b..e5685bd 100644 --- a/services/api.service.ts +++ b/services/api.service.ts @@ -107,7 +107,7 @@ export default class ApiService extends Service { page: 1, }, }; - this.broker.call("import.importComicsToDb", {walkedFolders, extractionOptions }); + this.broker.call("import.processAndImportToDB", {walkedFolders, extractionOptions }); }) .on("change", (path, stats) => logger.info( diff --git a/services/import.service.ts b/services/import.service.ts index 2ca43bb..cee6113 100644 --- a/services/import.service.ts +++ b/services/import.service.ts @@ -1,5 +1,5 @@ "use strict"; -import { isNil, map } from "lodash"; +import { each, forOwn, isNil, isUndefined, map } from "lodash"; import { Context, Service, @@ -64,8 +64,8 @@ export default class ImportService extends Service { return convertXMLToJSON("lagos"); }, }, - importComicsToDb: { - rest: "POST /importComicsToDB", + processAndImportToDB: { + rest: "POST /processAndImportToDB", bulkhead: { enabled: true, concurrency: 50, @@ -312,13 +312,56 @@ export default class ImportService extends Service { return await Comic.findById(ctx.params.id); }, }, - axn: { - rest: "GET /axn", + getComicBookGroups: { + rest: "GET /getComicBookGroups", params: {}, - async handler(ctx: Context<{path, stats}>) { - logger.info(ctx.params); - return {"pandurang": "hari"}; - } + async handler(ctx: Context<{}>) { + let volumesMetadata = []; + // 1. get volumes with issues mapped where issue count > 2 + const volumes = await Comic.aggregate([ + { + $group: { + _id: "$sourcedMetadata.comicvine.volume.id", + volumeURI: { + $last: "$sourcedMetadata.comicvine.volume.api_detail_url", + }, + count: { $sum: 1 }, + }, + }, + { + $match: { + count: { $gte: 2 }, + }, + }, + { $sort: { updatedAt: -1 } }, + { $skip: 0 }, + { $limit: 5 }, + ]); + // 2. Map over the aggregation result and get volume metadata from CV + // 2a. Make a call to comicvine-service + volumesMetadata = map( + volumes, + async (volume) => { + if (!isNil(volume.volumeURI)) { + return await ctx.call( + "comicvine.getVolumes", + { + volumeURI: volume.volumeURI, + data: { + format: "json", + fieldList: + "id,name,deck,api_detail_url", + limit: "1", + offset: "0", + }, + } + ); + } + } + ); + + return Promise.all(volumesMetadata); + }, }, }, methods: {