UNPKG

n8n-nodes-mallabe-currencies

Version:

n8n community node that allows you to convert / exchange currencies to other currencies as well as get the daily rates of currencies using Mallabe Currencies

135 lines 5.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MallabeCurrencies = void 0; const GenericFunctions_1 = require("./GenericFunctions"); const ConvertCurrencyOperation_1 = require("./ConvertCurrencyOperation"); const GetDailyRatesOperation_1 = require("./GetDailyRatesOperation"); class MallabeCurrencies { constructor() { this.description = { displayName: 'Mallabe Currencies', name: 'mallabeCurrencies', icon: 'file:mallabe.svg', group: ['transform'], version: 1, subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}', description: 'Mallabe Currencies is a utility tool that allows you to convert / exchange currencies to other currencies as well as get the daily rates of currencies.', defaults: { name: 'Mallabe Currencies', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'mallabeCurrenciesApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Currency', value: 'currency', }, ], default: 'currency', required: true, }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['currency'], }, }, options: [ { name: 'Convert Currency', value: 'convertCurrency', description: 'Convert a specified amount from one currency to another', action: 'Convert currency', }, { name: 'Get Daily Rates', value: 'getDailyRates', description: 'Get the daily exchange rates for a specified currency', action: 'Get daily rates', } ], default: 'convertCurrency', }, ...ConvertCurrencyOperation_1.convertCurrencyFields, ...GetDailyRatesOperation_1.getDailyRatesFields ], }; } async execute() { const items = this.getInputData(); const returnData = []; const length = items.length; const qs = {}; let response; let responseData; for (let i = 0; i < length; i++) { try { const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); if (resource === 'currency') { if (operation === 'convertCurrency') { const from = this.getNodeParameter('from', i); const to = this.getNodeParameter('to', i); const amount = this.getNodeParameter('amount', i); const date = this.getNodeParameter('date', i); const webhookUrl = this.getNodeParameter('webhookUrl', i); const body = { from, to, amount, date, webhookUrl, }; response = await GenericFunctions_1.mallabeCurrenciesRequest.call(this, 'POST', '/v1/currencies/convert', body, qs); } else if (operation === 'getDailyRates') { const from = this.getNodeParameter('from', i); const symbols = this.getNodeParameter('symbols', i); const date = this.getNodeParameter('date', i); const webhookUrl = this.getNodeParameter('webhookUrl', i); const body = { from, symbols, date, webhookUrl, }; response = await GenericFunctions_1.mallabeCurrenciesRequest.call(this, 'POST', '/v1/currencies/rates/daily', body, qs); } responseData = response; } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData); } else { returnData.push(responseData); } } catch (error) { if (this.continueOnFail()) { returnData.push({ error: error.message }); continue; } throw error; } } return [this.helpers.returnJsonArray(returnData)]; } } exports.MallabeCurrencies = MallabeCurrencies; //# sourceMappingURL=MallabeCurrencies.node.js.map