admin-api-aurum-connector
Version:
Module to connect to the Admin API Aurum Core
57 lines (46 loc) • 1.81 kB
JavaScript
const { module_name, configurations_key } = require("../../utils/Constants.js");
const { logger } = require("../../utils/Logger.js");
const updateInvestment = async (token, accountHolderId, body) => {
try {
logger.info(`module-hub-aurum-core-connector :: update investment "${module_name}" ...`);
if(!token) {
return {
responseCode: 401,
message: "A token is required to consume the API"
};
}
if(!accountHolderId) {
return {
responseCode: 400,
message: "accountHolderId is required to consume the API"
};
}
const config = global[configurations_key];
let endpoint = config?.investment?.updateInvestment?.endpoint || "";
endpoint = endpoint.replace("{mgtwUrl}", config.mgtwUrl);
endpoint = endpoint.replace("{branchId}", config.branchId);
endpoint = endpoint.replace("{accountHolderId}", accountHolderId);
logger.info(`module-hub-aurum-core-connector :: update investment to endpoint: ${endpoint}`);
body.branchId = config.branchId;
body.yieldPaymentOption = config?.investment?.updateInvestment?.yieldPaymentOption || 1;
const response = await fetch(endpoint, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + token
},
body: JSON.stringify(body)
});
const responseJson = await response.json();
logger.info(`module-hub-aurum-core-connector :: update investment response: ${JSON.stringify(responseJson)}`);
return responseJson;
} catch (error) {
logger.error(`module-hub-aurum-core-connector :: Error creating investment: ${error}`);
return {
responseCode: 500,
error: error,
message: "Error creating investment",
};
}
};
module.exports = updateInvestment;