a 09-Dec
This commit is contained in:
parent
00cb793a7c
commit
bc98edcb4b
|
|
@ -155,11 +155,11 @@ async function update_project_sf(req, res) {
|
||||||
// updateData.vaAssigned = newVaAssignedArray;
|
// updateData.vaAssigned = newVaAssignedArray;
|
||||||
|
|
||||||
// Calculate VAs to add and remove for relationship updates
|
// Calculate VAs to add and remove for relationship updates
|
||||||
const currentVaIds = existingProject.vaAssigned.map(va => va.toString());
|
const currentVaIds = existingProject.vaAssigned.map(va => va.vaId.toString());
|
||||||
const newVaIds = newVaAssignedArray.map(va => va.toString());
|
const newVaIds = newVaAssignedArray.map(va => va.toString());
|
||||||
|
|
||||||
const vaToAdd = newVaAssignedArray.filter(va => !currentVaIds.includes(va.toString()));
|
const vaToAdd = newVaAssignedArray.filter(va => !currentVaIds.includes(va.toString()));
|
||||||
const vaToRemove = existingProject.vaAssigned.filter(va => !newVaIds.includes(va.toString()));
|
const vaToRemove = existingProject.vaAssigned.filter(va => !newVaIds.includes(va.vaId.toString()));
|
||||||
|
|
||||||
// Update relationships for added VAs
|
// Update relationships for added VAs
|
||||||
if (vaToAdd.length > 0) {
|
if (vaToAdd.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ 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,
|
"leaveType": leaveType,
|
||||||
"comment": processedComment.plainText, // Send plain text to Salesforce
|
"comment": processedComment.plainText !== "" ? processedComment.plainText : "-", // Send plain text to Salesforce
|
||||||
"attachments": processedComment.extractedImages, // Send extracted images info
|
"attachments": processedComment.extractedImages, // Send extracted images info
|
||||||
"status": "PENDING",
|
"status": "PENDING",
|
||||||
"rejectionReason": ""
|
"rejectionReason": ""
|
||||||
|
|
@ -176,6 +176,7 @@ async function va_leave_apply_function(req, res) {
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
|
await LeavesModel.findByIdAndDelete(leaveRequest._id)
|
||||||
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ async function va_profile_update_callback(req, res) {
|
||||||
const allowedFields = [
|
const allowedFields = [
|
||||||
"firstName", "lastName", "dob", "age", "address",
|
"firstName", "lastName", "dob", "age", "address",
|
||||||
"city", "state", "country", "phone", "skype",
|
"city", "state", "country", "phone", "skype",
|
||||||
"paymentMethod", "payoneerAccount", "veemAccount"
|
"paymentMethod", "payoneerAccount", "veemAccount", "wiseEmail"
|
||||||
];
|
];
|
||||||
|
|
||||||
let hasUpdates = false;
|
let hasUpdates = false;
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ async function va_timesheet_adjustment_function(req, res) {
|
||||||
"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": processedComment.plainText, // Send plain text to Salesforce
|
"comment": processedComment.plainText !== "" ? processedComment.plainText : "-", // Send plain text to Salesforce
|
||||||
"attachments": processedComment.extractedImages, // Send extracted images info
|
"attachments": processedComment.extractedImages, // Send extracted images info
|
||||||
"status": "PENDING",
|
"status": "PENDING",
|
||||||
"rejectionReason": "",
|
"rejectionReason": "",
|
||||||
|
|
@ -167,6 +167,7 @@ async function va_timesheet_adjustment_function(req, res) {
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
|
await AdjustedHoursModel.findByIdAndDelete(adjustmentRequest._id)
|
||||||
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ async function updateEntityRelationships(data) {
|
||||||
if (vaId && Array.isArray(vaId)) {
|
if (vaId && Array.isArray(vaId)) {
|
||||||
await ProjectModel.findByIdAndUpdate(
|
await ProjectModel.findByIdAndUpdate(
|
||||||
projectId,
|
projectId,
|
||||||
{ $addToSet: { "vaAssigned.vaId": { $each: vaId } } }
|
{ $addToSet: { vaAssigned: { $each: vaId } } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ async function updateEntityRelationships(data) {
|
||||||
{ _id: { $in: projectId } },
|
{ _id: { $in: projectId } },
|
||||||
{
|
{
|
||||||
$addToSet: {
|
$addToSet: {
|
||||||
"vaAssigned.vaId": vaId
|
vaAssigned: vaId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -285,7 +285,7 @@ async function removeEntityRelationships(data) {
|
||||||
if (projectId && Array.isArray(projectId)) {
|
if (projectId && Array.isArray(projectId)) {
|
||||||
await ProjectModel.updateMany(
|
await ProjectModel.updateMany(
|
||||||
{ _id: { $in: projectId } },
|
{ _id: { $in: projectId } },
|
||||||
{ $pull: { "vaAssigned.vaId": vaId } }
|
{ $pull: { vaAssigned: vaId } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue