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; padding: 0 1.5rem;
gap: 1rem; gap: 1rem;
width: 100%; width: 100%;
max-width: 1024px;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
@ -188,7 +187,10 @@ body {
width: 16rem; width: 16rem;
background-color: var(--bg-card); background-color: var(--bg-card);
border-right: 1px solid var(--border-color); border-right: 1px solid var(--border-color);
display: none; /* display: none; */
}
.dashboard-sidebar.active {
display: block;
} }
@media (min-width: 768px) { @media (min-width: 768px) {
@ -196,6 +198,20 @@ body {
display: block; 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 { .sidebar-header {
padding: 1.5rem; padding: 1.5rem;

View File

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

View File

@ -46,17 +46,39 @@ async function updateEntityRelationships(data) {
results.vaUpdate = `Updated ${vaUpdateResult.modifiedCount} VAs`; 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 = {}; const projectUpdateData = {};
if (clientId) { if (clientId) {
projectUpdateData.clientId = 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) { if (Object.keys(projectUpdateData).length > 0) {
const projectUpdate = await ProjectModel.findByIdAndUpdate( const projectUpdate = await ProjectModel.findByIdAndUpdate(
projectId, projectId,
@ -215,14 +237,37 @@ async function removeEntityRelationships(data) {
// Remove projectId from VAs // Remove projectId from VAs
if (vaId && Array.isArray(vaId)) { if (vaId && Array.isArray(vaId)) {
await VAModel.updateMany( // await VAModel.updateMany(
{ _id: { $in: vaId } }, // { _id: { $in: vaId } },
{ $pull: { // { $pull: {
projectIds: projectId, // projectIds: projectId,
// 🐞🐞🐞 Here before removing we need to check if VA is still assigned to other projects of the same client // // 🐞🐞🐞 Here before removing we need to check if VA is still assigned to other projects of the same client
clientIds: clientId // 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'; results.projectRemoval = 'Project relationships removed successfully';

View File

@ -256,7 +256,7 @@
</td> </td>
<td> <td>
<div class="va-info"> <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 class="va-email">${va.email || 'N/A'}</div>
</div> </div>
</td> </td>
@ -352,6 +352,15 @@
setInterval(loadDashboardData, 30000); 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> </script>
</body> </body>
</html> </html>