UNPKG

admin-api-aurum-connector

Version:

Module to connect to the Admin API Aurum Core

47 lines (37 loc) 1.35 kB
const { module_name, configurations_key } = require("../../utils/Constants.js"); const { logger } = require("../../utils/Logger.js"); const unlock = async (token, body) => { try { logger.info(`module-hub-aurum-core-connector :: unlock "${module_name}" ...`); if(!token) { return { responseCode: 401, message: "A token is required to consume the API" }; } const config = global[configurations_key]; let endpoint = config?.card?.unlock?.endpoint || ""; endpoint = endpoint.replace("{mgtwUrl}", config.mgtwUrl); logger.info(`module-hub-aurum-core-connector :: card unlock to endpoint: ${endpoint}`); body.branchId = config.branchId; const response = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer " + token }, body: JSON.stringify(body) }); const responseJson = await response.json(); logger.info(`module-hub-aurum-core-connector :: card unlock response: ${JSON.stringify(responseJson)}`); return responseJson; } catch (error) { logger.error(`module-hub-aurum-core-connector :: card unlock investment: ${error}`); return { responseCode: 500, error: error, message: "Error card unlock", }; } }; module.exports = unlock;