UNPKG

open-api-aurum-connector2

Version:

Module to connect to the OPEN API Aurum Core

51 lines (40 loc) 1.88 kB
const { module_name, configurations_key } = require("../../utils/Constants.js"); const { logger } = require("../../utils/Logger.js"); //this method requiere user autentication, not clients const getTransactionsByAccountId = async (token, accountId, parametters) => { try { logger.info(`module-hub-aurum-core-connector :: getTransactionsByAccountId "${module_name}" ...`); const config = global[configurations_key]; let endpoint = config?.accounts?.getTransactionsByAccountId?.endpoint || ""; //replace endpoint with the correct values endpoint = endpoint.replace("{mgtwUrl}", config.mgtwUrl); endpoint = endpoint.replace("{tenantName}", config.tenantName); endpoint = endpoint.replace("{accountId}", accountId); logger.info(`module-hub-aurum-core-connector :: getTransactionsByAccountId to endpoint: ${endpoint}`); logger.info(`module-hub-aurum-core-connector :: getTransactionsByAccountId to accountId: ${accountId}`); logger.info(`module-hub-aurum-core-connector :: getTransactionsByAccountId to token: ${token}`); //add parametters to the endpoint if (parametters) { endpoint = endpoint + "?" + parametters; } const response = await fetch(endpoint, { method: "GET", headers: { "Content-Type": "application/json", "Authorization": "Bearer " + token, }, }); //PARSE RESPONSE const responseJson = await response.json(); logger.info(`module-hub-aurum-core-connector :: Response: ${JSON.stringify(responseJson)}`); return responseJson; } catch (error) { logger.error(`module-hub-aurum-core-connector :: Error getting transactions by account id: ${error}`); return { responseCode: 500, error: error, error_description: "Error getting transactions by account id", }; } }; module.exports = getTransactionsByAccountId;