vista-co
Version:
47 lines (46 loc) • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
const axios_master_1 = require("axios-master");
// Implementation Notes: This function fetches the details of a background job from the OData service.
// It accepts the backgroundJobId as a path parameter and optional headers for authentication and region code.
const GetBackgroundJobDetails = async (backgroundJobId) => {
var _a, _b, _c;
try {
// Construct the request URL with the backgroundJobId path parameter.
const url = `${__1.config.host}/WSVistaWebClient/OData.svc/BackgroundJob.svc/${backgroundJobId}`;
// Send the GET request with headers including API token and region code if provided.
const res = await (0, axios_master_1.axiosMasterMain)({
method: "GET",
url,
headers: {
connectapitoken: `${__1.config.token}`, // API token for authentication
"Content-Type": "application/json", // Ensures the response format is JSON
"Connect-Region-Code": __1.config.regionCode, // Region code for localization
},
}, {
name: "GetBackgroundJobDetails", // Request identifier for logging and debugging
timeout: 20000, // Timeout of 20 seconds for the request
logger(data) {
if (__1.config.logger) {
console.log(data); // Logs request data for debugging purposes
}
},
});
// Return the 'data' from the successful response.
return {
success: true,
message: "Request successful",
data: res,
};
}
catch (error) {
// Logs and returns an error message if the request fails.
console.error("Request failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data);
return {
success: false,
message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred",
};
}
};
exports.default = { GetBackgroundJobDetails };