Fixed js error in client register
This commit is contained in:
parent
227d591e68
commit
e9cba202f1
|
|
@ -83,26 +83,26 @@ async function project_add_sf(req, res) {
|
||||||
|
|
||||||
// Send data to Salesforce API after successful registration
|
// Send data to Salesforce API after successful registration
|
||||||
try {
|
try {
|
||||||
// const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/`;
|
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/`;
|
||||||
|
|
||||||
// const response = await fetch(salesforceUrl, {
|
const response = await fetch(salesforceUrl, {
|
||||||
// method: 'POST',
|
method: 'POST',
|
||||||
// headers: {
|
headers: {
|
||||||
// 'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
// },
|
},
|
||||||
// body: JSON.stringify(created)
|
body: JSON.stringify(created)
|
||||||
// });
|
});
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
// res.status(201).json({ success: true, data: created, SyncSalesforce: result });
|
res.status(201).json({ success: true, data: created, SyncSalesforce: result });
|
||||||
res.status(201).json({ success: true, data: created, relationships: relationshipUpdate });
|
// res.status(201).json({ success: true, data: created, relationships: relationshipUpdate });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("❌ Failed to sync with Salesforce:", error.message);
|
console.error("❌ Failed to sync with Salesforce:", error.message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,80 +144,80 @@ 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/timesheet-adjustment`;
|
||||||
// const sfData = {
|
const sfData = {
|
||||||
// "id": adjustmentRequest._id,
|
"id": adjustmentRequest._id,
|
||||||
// "va": {
|
"va": {
|
||||||
// "id": vaId
|
"id": vaId
|
||||||
// },
|
},
|
||||||
// "project": {
|
"project": {
|
||||||
// "id": projectId
|
"id": projectId
|
||||||
// },
|
},
|
||||||
// "date": adjustmentDate.toISOString().split('T')[0],
|
"date": adjustmentDate.toISOString().split('T')[0],
|
||||||
// "loginTime": loginDateTime.toISOString(),
|
"loginTime": loginDateTime.toISOString(),
|
||||||
// "logoutTime": logoutDateTime.toISOString(),
|
"logoutTime": logoutDateTime.toISOString(),
|
||||||
// "comment": comment,
|
"comment": comment,
|
||||||
// "status": "PENDING",
|
"status": "PENDING",
|
||||||
// "rejectionReason": "",
|
"rejectionReason": "",
|
||||||
// "adjustedHours": formatTime(adjustedSeconds)
|
"adjustedHours": formatTime(adjustedSeconds)
|
||||||
// }
|
|
||||||
|
|
||||||
// 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}`);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const result = await response.json();
|
|
||||||
// // console.log("✅ Successfully synced VA data to Salesforce:", result);
|
|
||||||
|
|
||||||
// return res.status(201).json({
|
|
||||||
// success: true,
|
|
||||||
// message: "Adjustment request submitted successfully",
|
|
||||||
// data: {
|
|
||||||
// adjustmentId: adjustmentRequest._id,
|
|
||||||
// date: adjustmentDate.toISOString().split('T')[0],
|
|
||||||
// loginTime: loginDateTime.toISOString(),
|
|
||||||
// logoutTime: logoutDateTime.toISOString(),
|
|
||||||
// adjustedHours: formatTime(adjustedSeconds),
|
|
||||||
// comment: comment,
|
|
||||||
// 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"
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
// console.log("✅ Successfully synced VA data to Salesforce:", result);
|
||||||
|
|
||||||
|
return res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
message: "Adjustment request submitted successfully",
|
||||||
|
data: {
|
||||||
|
adjustmentId: adjustmentRequest._id,
|
||||||
|
date: adjustmentDate.toISOString().split('T')[0],
|
||||||
|
loginTime: loginDateTime.toISOString(),
|
||||||
|
logoutTime: logoutDateTime.toISOString(),
|
||||||
|
adjustedHours: formatTime(adjustedSeconds),
|
||||||
|
comment: comment,
|
||||||
|
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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue