Added payslip API

This commit is contained in:
Aakash Mittal 2025-11-28 13:15:25 +05:30
parent 870d81e2ca
commit 9de7384020
2 changed files with 43 additions and 9 deletions

View File

@ -1,12 +1,46 @@
import { VAModel } from "../../../models/vaModel.js";
async function va_payslip_data_function(req, res) { async function va_payslip_data_function(req, res) {
try { try {
// Assuming we have a service function to get payroll schedule const vaId = req.params.vaId;
const payrollSchedule = await getPayrollScheduleForVA(req.user.id);
return res.status(200).json({ success: true, data: payrollSchedule }); const vaUser = await VAModel.findById(vaId);
} catch (error) { if (!vaUser) {
console.error("Error fetching payroll schedule:", error); return res.status(404).json({ success: false, message: "VA not found" });
return res.status(500).json({ success: false, message: "Internal Server Error" }); }
}
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-payslip?vaId=${vaId}`;
const response = await fetch(salesforceUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
// Add any required headers for Salesforce authentication
// 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
},
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
}
const result = await response.json();
// console.log("✅ Successfully synced VA data to Salesforce:", result);
res.status(201).json({
success: true,
result
});
} catch (error) {
console.error("Failed to sync with Salesforce:", error.message);
console.log(error)
// Create a custom error to distinguish Salesforce errors
const salesforceError = new Error(`Salesforce sync failed: ${error.message}`);
salesforceError.isSalesforceError = true;
throw salesforceError;
}
} }
export { va_payslip_data_function }; export { va_payslip_data_function };

View File

@ -28,7 +28,7 @@ import { va_leave_list_function } from "../../controllers/va/vaLeaves/vaLeaveLis
import { va_leave_manage_function } from "../../controllers/va/vaLeaves/vaLeaveManage.controller.js"; import { va_leave_manage_function } from "../../controllers/va/vaLeaves/vaLeaveManage.controller.js";
import { va_remove_function } from "../../controllers/va/vaProfile/vaDelete.controller.js"; import { va_remove_function } from "../../controllers/va/vaProfile/vaDelete.controller.js";
import { va_payroll_schedule_function } from "../../controllers/va/vaPayroll/vaPayrollSchedule.controller.js"; import { va_payroll_schedule_function } from "../../controllers/va/vaPayroll/vaPayrollSchedule.controller.js";
// import { va_payslip_data_function } from "../../controllers/va/vaPayroll/vaPaySlip.controller.js"; import { va_payslip_data_function } from "../../controllers/va/vaPayroll/vaPaySlip.controller.js";
vaRoutes.get("/", va_callback); // VA Callback for getting active VA vaRoutes.get("/", va_callback); // VA Callback for getting active VA
@ -82,7 +82,7 @@ vaRoutes.get("/log/project/:projectId/:from?/:to?", authValidator, va_log_callba
// Payroll routes // Payroll routes
vaRoutes.get("/payrollSchedule", authValidator, va_payroll_schedule_function); // VA Payroll Schedule vaRoutes.get("/payrollSchedule", authValidator, va_payroll_schedule_function); // VA Payroll Schedule
// vaRoutes.get("/paySlip/:vaId", authValidator, va_payslip_data_function); // VA Payslip vaRoutes.get("/paySlip/:vaId", authValidator, va_payslip_data_function); // VA Payslip