🦸🏻 Added metron service

This commit is contained in:
2022-01-04 07:39:00 -08:00
parent ba31650543
commit 4d1b4ceb71
3 changed files with 51 additions and 81 deletions

View File

@@ -0,0 +1,44 @@
"use strict";
import { Service, ServiceBroker, Context } from "moleculer";
import axios from "axios";
const METRON_BASE_URL = "https://metron.cloud/api/";
export default class MetronService extends Service {
public constructor(public broker: ServiceBroker) {
super(broker);
this.parseServiceSchema({
name: "metron",
actions: {
fetchResource: {
rest: "POST /fetchResource",
params: {},
handler: async (
ctx: Context<{
resource: string;
method: string;
query: {
name: string;
page: number;
};
}>
) => {
console.log(ctx.params);
const results = await axios({
method: "GET",
url: `https://metron.cloud/api/${ctx.params.resource}`,
params: {
name: ctx.params.query.name,
page: ctx.params.query.page,
},
});
return results.data;
},
},
},
methods: {},
});
}
}