Compare commits
2 Commits
2ca5146846
...
c04264f054
| Author | SHA1 | Date |
|---|---|---|
|
|
c04264f054 | |
|
|
a7d770498c |
|
|
@ -6,7 +6,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon --inspect src/server.js",
|
"start": "nodemon --inspect src/server.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"deploy": "curl -X POST http://16.170.168.132:9000/hooks/deploy-va-middleware",
|
"deploy": "curl -X POST http://35.162.222.18:9000/hooks/deploy-va-middleware",
|
||||||
"build": "npx webpack --mode production",
|
"build": "npx webpack --mode production",
|
||||||
"dev": "npx webpack --mode development"
|
"dev": "npx webpack --mode development"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -147,64 +147,40 @@ async function va_leave_apply_function(req, res) {
|
||||||
await leaveRequest.save();
|
await leaveRequest.save();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/timesheet-adjustment`;
|
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/leave-request`;
|
||||||
// const sfData = {
|
const sfData = {
|
||||||
// "id": leaveRequest._id,
|
"leaveId": leaveRequest._id.toString(),
|
||||||
// "va": {
|
// "va": {
|
||||||
// "id": vaId
|
// "id": vaId
|
||||||
// },
|
// },
|
||||||
// "dateFrom": startDate.toISOString().split('T')[0],
|
"va": vaId.toString(),
|
||||||
// "dateTo": endDate.toISOString().split('T')[0],
|
"dateFrom": startDate.toISOString().split('T')[0],
|
||||||
// "totalDays": totalDays,
|
"dateTo": endDate.toISOString().split('T')[0],
|
||||||
// "leaveType": leaveType,
|
"totalDays": totalDays,
|
||||||
// "comment": processedComment.plainText, // Send plain text to Salesforce
|
"leaveType": leaveType,
|
||||||
// "attachments": processedComment.extractedImages, // Send extracted images info
|
"comment": processedComment.plainText, // Send plain text to Salesforce
|
||||||
// "status": "PENDING",
|
"attachments": processedComment.extractedImages, // Send extracted images info
|
||||||
// "rejectionReason": ""
|
"status": "PENDING",
|
||||||
// }
|
"rejectionReason": ""
|
||||||
|
}
|
||||||
|
|
||||||
// const response = await fetch(salesforceUrl, {
|
const response = await fetch(salesforceUrl, {
|
||||||
// method: 'POST',
|
method: 'POST',
|
||||||
// headers: {
|
headers: {
|
||||||
// 'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
// // Add any required headers for Salesforce authentication
|
// Add any required headers for Salesforce authentication
|
||||||
// // 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
|
// 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
|
||||||
// },
|
},
|
||||||
// body: JSON.stringify({"data": sfData})
|
body: JSON.stringify({ "data": sfData })
|
||||||
// });
|
});
|
||||||
|
|
||||||
// if (!response.ok) {
|
if (!response.ok) {
|
||||||
// const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
// throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// const result = await response.json();
|
// const result = await response.json();
|
||||||
// // console.log("✅ Successfully synced VA data to Salesforce:", result);
|
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return res.status(201).json({
|
// return res.status(201).json({
|
||||||
// success: true,
|
// success: true,
|
||||||
|
|
@ -215,10 +191,35 @@ async function va_leave_apply_function(req, res) {
|
||||||
// dateTo: endDate.toISOString().split('T')[0],
|
// dateTo: endDate.toISOString().split('T')[0],
|
||||||
// totalDays: totalDays,
|
// totalDays: totalDays,
|
||||||
// leaveType,
|
// leaveType,
|
||||||
// comment,
|
// comment: processedComment.processedHTML,
|
||||||
|
// // attachments: processedComment.extractedImages,
|
||||||
// status: "PENDING"
|
// 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) {
|
} catch (error) {
|
||||||
console.error("Leave apply error:", error);
|
console.error("Leave apply error:", error);
|
||||||
|
|
|
||||||
|
|
@ -138,12 +138,12 @@ async function va_timesheet_adjustment_function(req, res) {
|
||||||
try {
|
try {
|
||||||
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/timesheet-adjustment`;
|
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/timesheet-adjustment`;
|
||||||
const sfData = {
|
const sfData = {
|
||||||
"id": adjustmentRequest._id,
|
"id": adjustmentRequest._id.toString(),
|
||||||
"va": {
|
"va": {
|
||||||
"id": vaId
|
"id": vaId.toString()
|
||||||
},
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"id": projectId
|
"id": projectId.toString()
|
||||||
},
|
},
|
||||||
"date": adjustmentDate.toISOString().split('T')[0],
|
"date": adjustmentDate.toISOString().split('T')[0],
|
||||||
"loginTime": loginDateTime.toISOString(),
|
"loginTime": loginDateTime.toISOString(),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>Download DocTracker</title>
|
<title>DocTracker</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue