This commit is contained in:
@@ -7,7 +7,8 @@ const https = require("https");
|
||||
var bcrypt = require("bcryptjs");
|
||||
const { splitSite } = require("../middlewares");
|
||||
const SYSTEM_ACCESS_PERMISSION = "System Access";
|
||||
const HR_EMPLOYEE_LIST_ENDPOINT = "https://ws-hr.mayosolution.com/api/integration/employees/list";
|
||||
const HR_EMPLOYEE_LIST_ENDPOINT = "https://ws-hr.mayosolution.com/api/integration/employees";
|
||||
const HR_EMPLOYEE_LIST_FALLBACK_ENDPOINT = "https://ws-hr.mayosolution.com/api/integration/employees/list";
|
||||
const HR_INTEGRATION_USERNAME = "vibecodingking";
|
||||
const HR_INTEGRATION_PASSWORD = "oAQC483f1jxdJdoJcd0kCAd7C";
|
||||
const HR_INSECURE_HTTPS_AGENT = new https.Agent({ rejectUnauthorized: false });
|
||||
@@ -322,22 +323,32 @@ exports.getEmployeesWithUsernameOrEmail = (req, res) => {
|
||||
};
|
||||
|
||||
exports.getExternalEmployeesList = async (req, res) => {
|
||||
const requestBody = {
|
||||
username: HR_INTEGRATION_USERNAME,
|
||||
password: HR_INTEGRATION_PASSWORD,
|
||||
status: "active"
|
||||
};
|
||||
const requestOptions = {
|
||||
timeout: 15000,
|
||||
httpsAgent: HR_INSECURE_HTTPS_AGENT
|
||||
};
|
||||
try {
|
||||
console.log("[HR Integration] Requesting employee list from:", HR_EMPLOYEE_LIST_ENDPOINT);
|
||||
const response = await axios.post(
|
||||
HR_EMPLOYEE_LIST_ENDPOINT,
|
||||
{
|
||||
username: HR_INTEGRATION_USERNAME,
|
||||
password: HR_INTEGRATION_PASSWORD,
|
||||
status: "active"
|
||||
},
|
||||
{
|
||||
timeout: 15000,
|
||||
httpsAgent: HR_INSECURE_HTTPS_AGENT
|
||||
let response = await axios.post(HR_EMPLOYEE_LIST_ENDPOINT, requestBody, requestOptions);
|
||||
let list = Array.isArray(response?.data) ? response.data : [];
|
||||
|
||||
// Backward compatibility for older integration endpoint naming.
|
||||
if (list.length === 0) {
|
||||
console.log("[HR Integration] Empty result, retrying fallback endpoint:", HR_EMPLOYEE_LIST_FALLBACK_ENDPOINT);
|
||||
const fallbackResponse = await axios.post(HR_EMPLOYEE_LIST_FALLBACK_ENDPOINT, requestBody, requestOptions);
|
||||
const fallbackList = Array.isArray(fallbackResponse?.data) ? fallbackResponse.data : [];
|
||||
if (fallbackList.length > 0) {
|
||||
response = fallbackResponse;
|
||||
list = fallbackList;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
console.log("[HR Integration] /employees/list response:", response?.data);
|
||||
const list = Array.isArray(response?.data) ? response.data : [];
|
||||
res.send(list);
|
||||
} catch (err) {
|
||||
console.log("[HR Integration] /employees/list error status:", err?.response?.status);
|
||||
|
||||
Reference in New Issue
Block a user