admin-api-aurum-connector
Version:
Module to connect to the Admin API Aurum Core
41 lines (34 loc) • 1.41 kB
JavaScript
const { module_name, configurations_key } = require("../../utils/Constants.js");
const { logger } = require("../../utils/Logger.js");
//this method requiere user autentication, not clients
const updateAccount = async (token, accountId, body) => {
try {
logger.info(`module-hub-aurum-core-connector :: updateAccount "${module_name}" ...`);
const config = global[configurations_key];
let endpoint = config?.accounts?.updateAccount?.endpoint || "";
//replace endpoint with the correct values
endpoint = endpoint.replace("{mgtwUrl}", config.mgtwUrl);
endpoint = endpoint.replace("{accountId}", accountId);
logger.info(`module-hub-aurum-core-connector :: updateAccount to endpoint: ${endpoint}`);
const response = await fetch(endpoint, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + token,
},
body: JSON.stringify(body),
});
//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 updating account: ${error}`);
return {
responseCode: 500,
error: error,
error_description: "Error updating account",
};
}
};
module.exports = updateAccount;