📚 Added an endpoint to get CV-mapped volumes
This commit is contained in:
@@ -76,7 +76,7 @@ const brokerConfig: BrokerOptions = {
|
|||||||
// More info: https://moleculer.services/docs/0.14/networking.html
|
// 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.
|
// 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.
|
// In production you can set it via `TRANSPORTER=nats://localhost:4222` environment variable.
|
||||||
transporter: null, // "NATS"
|
transporter: "NATS", // "NATS"
|
||||||
|
|
||||||
// Define a cacher.
|
// Define a cacher.
|
||||||
// More info: https://moleculer.services/docs/0.14/caching.html
|
// More info: https://moleculer.services/docs/0.14/caching.html
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export default class ApiService extends Service {
|
|||||||
page: 1,
|
page: 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
this.broker.call("import.importComicsToDb", {walkedFolders, extractionOptions });
|
this.broker.call("import.processAndImportToDB", {walkedFolders, extractionOptions });
|
||||||
})
|
})
|
||||||
.on("change", (path, stats) =>
|
.on("change", (path, stats) =>
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import { isNil, map } from "lodash";
|
import { each, forOwn, isNil, isUndefined, map } from "lodash";
|
||||||
import {
|
import {
|
||||||
Context,
|
Context,
|
||||||
Service,
|
Service,
|
||||||
@@ -64,8 +64,8 @@ export default class ImportService extends Service {
|
|||||||
return convertXMLToJSON("lagos");
|
return convertXMLToJSON("lagos");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
importComicsToDb: {
|
processAndImportToDB: {
|
||||||
rest: "POST /importComicsToDB",
|
rest: "POST /processAndImportToDB",
|
||||||
bulkhead: {
|
bulkhead: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
concurrency: 50,
|
concurrency: 50,
|
||||||
@@ -312,13 +312,56 @@ export default class ImportService extends Service {
|
|||||||
return await Comic.findById(ctx.params.id);
|
return await Comic.findById(ctx.params.id);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
axn: {
|
getComicBookGroups: {
|
||||||
rest: "GET /axn",
|
rest: "GET /getComicBookGroups",
|
||||||
params: {},
|
params: {},
|
||||||
async handler(ctx: Context<{path, stats}>) {
|
async handler(ctx: Context<{}>) {
|
||||||
logger.info(ctx.params);
|
let volumesMetadata = [];
|
||||||
return {"pandurang": "hari"};
|
// 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: {
|
methods: {
|
||||||
|
|||||||
Reference in New Issue
Block a user