Compare commits

..

No commits in common. "c04264f054e3a117f0a4d35565cc8345ce6181c5" and "2ca51468460be4ffb8e124e65a9599657abc046e" have entirely different histories.

4 changed files with 106 additions and 107 deletions

View File

@ -6,7 +6,7 @@
"scripts": {
"start": "nodemon --inspect src/server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"deploy": "curl -X POST http://35.162.222.18:9000/hooks/deploy-va-middleware",
"deploy": "curl -X POST http://16.170.168.132:9000/hooks/deploy-va-middleware",
"build": "npx webpack --mode production",
"dev": "npx webpack --mode development"
},

View File

@ -147,65 +147,39 @@ async function va_leave_apply_function(req, res) {
await leaveRequest.save();
try {
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/leave-request`;
const sfData = {
"leaveId": leaveRequest._id.toString(),
// const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/timesheet-adjustment`;
// const sfData = {
// "id": leaveRequest._id,
// "va": {
// "id": vaId
// },
"va": vaId.toString(),
"dateFrom": startDate.toISOString().split('T')[0],
"dateTo": endDate.toISOString().split('T')[0],
"totalDays": totalDays,
"leaveType": leaveType,
"comment": processedComment.plainText, // Send plain text to Salesforce
"attachments": processedComment.extractedImages, // Send extracted images info
"status": "PENDING",
"rejectionReason": ""
}
// "dateFrom": startDate.toISOString().split('T')[0],
// "dateTo": endDate.toISOString().split('T')[0],
// "totalDays": totalDays,
// "leaveType": leaveType,
// "comment": processedComment.plainText, // Send plain text to Salesforce
// "attachments": processedComment.extractedImages, // Send extracted images info
// "status": "PENDING",
// "rejectionReason": ""
// }
const response = await fetch(salesforceUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// Add any required headers for Salesforce authentication
// 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
},
body: JSON.stringify({ "data": sfData })
});
// const response = await fetch(salesforceUrl, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// // Add any required headers for Salesforce authentication
// // 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
// },
// body: JSON.stringify({"data": sfData})
// });
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
}
// 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);
// return res.status(201).json({
// success: true,
// message: "Leave request submitted successfully",
// data: {
// leaveId: leaveRequest._id,
// dateFrom: startDate.toISOString().split('T')[0],
// dateTo: endDate.toISOString().split('T')[0],
// totalDays: totalDays,
// leaveType,
// comment: processedComment.processedHTML,
// // attachments: processedComment.extractedImages,
// status: "PENDING"
// },
// // SyncSalesforce: 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;
}
// // console.log("✅ Successfully synced VA data to Salesforce:", result);
return res.status(201).json({
success: true,
@ -216,10 +190,35 @@ async function va_leave_apply_function(req, res) {
dateTo: endDate.toISOString().split('T')[0],
totalDays: totalDays,
leaveType,
comment,
comment: processedComment.processedHTML,
// attachments: processedComment.extractedImages,
status: "PENDING"
}
},
// SyncSalesforce: 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;
}
// return res.status(201).json({
// success: true,
// message: "Leave request submitted successfully",
// data: {
// leaveId: leaveRequest._id,
// dateFrom: startDate.toISOString().split('T')[0],
// dateTo: endDate.toISOString().split('T')[0],
// totalDays: totalDays,
// leaveType,
// comment,
// status: "PENDING"
// }
// });
} catch (error) {
console.error("Leave apply error:", error);

View File

@ -138,12 +138,12 @@ async function va_timesheet_adjustment_function(req, res) {
try {
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/timesheet-adjustment`;
const sfData = {
"id": adjustmentRequest._id.toString(),
"id": adjustmentRequest._id,
"va": {
"id": vaId.toString()
"id": vaId
},
"project": {
"id": projectId.toString()
"id": projectId
},
"date": adjustmentDate.toISOString().split('T')[0],
"loginTime": loginDateTime.toISOString(),

View File

@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DocTracker</title>
<title>Download DocTracker</title>
<style>
body {