diff --git a/public/css/dashboard.css b/public/css/dashboard.css index 4bfd24f..c56f08c 100644 --- a/public/css/dashboard.css +++ b/public/css/dashboard.css @@ -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; diff --git a/src/controllers/va/vaAuth/vaLogin.controller.js b/src/controllers/va/vaAuth/vaLogin.controller.js index 2bd329f..7e00699 100644 --- a/src/controllers/va/vaAuth/vaLogin.controller.js +++ b/src/controllers/va/vaAuth/vaLogin.controller.js @@ -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); diff --git a/src/helper/updateEntityRelationships.js b/src/helper/updateEntityRelationships.js index a689f87..2de29d3 100644 --- a/src/helper/updateEntityRelationships.js +++ b/src/helper/updateEntityRelationships.js @@ -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'; diff --git a/views/client/dashboard-dashboard.ejs b/views/client/dashboard-dashboard.ejs index 091dc6b..640438c 100644 --- a/views/client/dashboard-dashboard.ejs +++ b/views/client/dashboard-dashboard.ejs @@ -256,7 +256,7 @@