💽 mongo import endpoint

This commit is contained in:
2021-06-02 09:02:32 -07:00
parent 56a8165368
commit 06d0c6aa72
9 changed files with 175 additions and 40 deletions

View File

@@ -22,6 +22,20 @@ export default class ApiService extends Service {
// Access to any actions in all services under "/api" URL
"**",
],
cors: {
origin: "*",
methods: [
"GET",
"OPTIONS",
"POST",
"PUT",
"DELETE",
],
allowedHeaders: ["*"],
exposedHeaders: [],
credentials: false,
maxAge: 3600,
},
use: [],
mergeParams: true,
autoAliases: true,
@@ -59,7 +73,6 @@ export default class ApiService extends Service {
logRequestParams: null,
// Logging the response data. Set to any log level to enable it. E.g. "info"
logResponseData: null,
// Serve assets from "public" folder
assets: {
folder: "public",
// Options to `server-static` module
@@ -105,10 +118,10 @@ export default class ApiService extends Service {
folder
);
client.emit("comicBookCoverMetadata", {
data: comicBookCoverMetadata,
status: "Done!",
});
client.emit(
"comicBookCoverMetadata",
comicBookCoverMetadata
);
});
case "single":

View File

@@ -3,6 +3,7 @@ import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
import { DbMixin } from "../mixins/db.mixin";
import Comic from "../models/comic.model";
import { walkFolder } from "../utils/uncompression.utils";
import { convertXMLToJSON } from "../utils/xml.utils";
export default class ProductsService extends Service {
// @ts-ignore
@@ -41,6 +42,31 @@ export default class ProductsService extends Service {
);
},
},
convertXMLToJSON: {
rest: "POST /convertXmlToJson",
params: {},
async handler(ctx: Context<{}>) {
return convertXMLToJSON("lagos");
},
},
rawImportToDB: {
rest: "POST /rawImportToDB",
params: { payload: "object" },
async handler(ctx: Context<{ payload: object }>) {
return new Promise((resolve, reject) => {
Comic.create(
ctx.params.payload,
(error, data) => {
if (data) {
resolve(data);
} else if (error) {
reject(new Error(error));
}
}
);
});
},
},
},
methods: {},
},