Fixed issues and bugs

This commit is contained in:
Aakash Mittal 2025-11-21 16:38:31 +05:30
parent bbc9793614
commit dc085787a3
4 changed files with 128 additions and 53 deletions

View File

@ -80,7 +80,6 @@ body {
padding: 0 1.5rem;
gap: 1rem;
width: 100%;
max-width: 1024px;
flex-direction: row;
align-items: center;
justify-content: space-between;
@ -188,7 +187,10 @@ body {
width: 16rem;
background-color: var(--bg-card);
border-right: 1px solid var(--border-color);
display: none;
/* display: none; */
}
.dashboard-sidebar.active {
display: block;
}
@media (min-width: 768px) {
@ -196,6 +198,20 @@ body {
display: block;
}
}
@media (max-width: 768px) {
.dashboard-sidebar {
position: absolute;
left: 0;
bottom: 0;
z-index: 99;
top: 0;
transform: translateX(-100%);
transition: .3s ease;
}
.dashboard-sidebar.active {
transform: translateX(0);
}
}
.sidebar-header {
padding: 1.5rem;

View File

@ -42,49 +42,54 @@ async function closePreviousSession(vaId, lastLog) {
});
// console.log(`Created logout log: ${logoutLog._id}`);
try {
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-project-log`;
const sfDataSync = {
"_id": logoutLog._id,
"loggedType": "LOGOUT",
"vaId": vaId,
"vaEmail": lastLog.vaEmail,
"projectId": lastLog.projectId,
"time": logoutLog.time,
}
// try {
// const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-project-log`;
// const sfDataSync = {
// "_id": logoutLog._id,
// "loggedType": "LOGOUT",
// "vaId": vaId,
// "vaEmail": lastLog.vaEmail,
// "projectId": lastLog.projectId,
// "time": logoutLog.time,
// }
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(sfDataSync)
});
// 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(sfDataSync)
// });
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);
// const result = await response.json();
// // console.log("✅ Successfully synced VA data to Salesforce:", result);
return {
// return {
// closedWorkTracks: openWorkTracks.length,
// logoutLogId: logoutLog._id,
// 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 {
closedWorkTracks: openWorkTracks.length,
logoutLogId: logoutLog._id,
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;
}
} catch (error) {
console.error("Error closing previous session:", error);

View File

@ -46,17 +46,39 @@ async function updateEntityRelationships(data) {
results.vaUpdate = `Updated ${vaUpdateResult.modifiedCount} VAs`;
}
// Update Project with clientId and vaId
// // Update Project with clientId and vaId
// const projectUpdateData = {};
// if (clientId) {
// projectUpdateData.clientId = clientId;
// }
// // 🐞🐞🐞 Here Duplicate Entry of Va is Created if SF pass same va multiple times in same req
// if (vaId && Array.isArray(vaId)) {
// projectUpdateData.vaAssigned = vaId;
// }
// if (Object.keys(projectUpdateData).length > 0) {
// const projectUpdate = await ProjectModel.findByIdAndUpdate(
// projectId,
// projectUpdateData,
// { new: true }
// );
// results.projectUpdate = projectUpdate ? 'Project updated successfully' : 'Project not found';
// }
if (vaId && Array.isArray(vaId)) {
await ProjectModel.findByIdAndUpdate(
projectId,
{ $addToSet: { vaAssigned: { $each: vaId } } }
);
}
// Update other fields normally
const projectUpdateData = {};
if (clientId) {
projectUpdateData.clientId = clientId;
}
// 🐞🐞🐞 Here Duplicate Entry of Va is Created if SF pass same va multiple times in same req
if (vaId && Array.isArray(vaId)) {
projectUpdateData.vaAssigned = vaId;
}
if (Object.keys(projectUpdateData).length > 0) {
const projectUpdate = await ProjectModel.findByIdAndUpdate(
projectId,
@ -215,14 +237,37 @@ async function removeEntityRelationships(data) {
// Remove projectId from VAs
if (vaId && Array.isArray(vaId)) {
await VAModel.updateMany(
{ _id: { $in: vaId } },
{ $pull: {
projectIds: projectId,
// 🐞🐞🐞 Here before removing we need to check if VA is still assigned to other projects of the same client
clientIds: clientId
}}
);
// await VAModel.updateMany(
// { _id: { $in: vaId } },
// { $pull: {
// projectIds: projectId,
// // 🐞🐞🐞 Here before removing we need to check if VA is still assigned to other projects of the same client
// clientIds: clientId
// }}
// );
for (const va of vaId) {
// Check if VA is still assigned to other projects of the same client
const otherProjectsWithSameClient = await ProjectModel.countDocuments({
_id: { $ne: projectId },
clientId: clientId,
vaAssigned: va
});
// Prepare update operation
const updateOperation = {
$pull: { projectIds: projectId }
};
// Only remove clientId if VA is not assigned to any other projects from this client
if (!otherProjectsWithSameClient) {
updateOperation.$pull = {
...updateOperation.$pull,
clientIds: clientId
};
}
await VAModel.findByIdAndUpdate(va, updateOperation);
}
}
results.projectRemoval = 'Project relationships removed successfully';

View File

@ -256,7 +256,7 @@
</td>
<td>
<div class="va-info">
<div class="va-name">${va.firstName} ${va.lastName}</div>
<div class="va-name">${va.name}</div>
<div class="va-email">${va.email || 'N/A'}</div>
</div>
</td>
@ -350,6 +350,15 @@
// Optional: Auto-refresh data every 30 seconds
setInterval(loadDashboardData, 30000);
document.addEventListener('DOMContentLoaded', () => {
var menuToggle = document.querySelector('.mobile-menu-button');
var sidebar = document.querySelector('.dashboard-sidebar');
menuToggle.addEventListener('click', () => {
sidebar.classList.toggle('active')
})
})
</script>