diff --git a/public/js/va-client-register.js b/public/js/va-client-register.js index 650beed..a9d6788 100644 --- a/public/js/va-client-register.js +++ b/public/js/va-client-register.js @@ -166,7 +166,7 @@ function validateCVV(cvv, cardType) { } // ZIP code validation -function validateZipCode(zipCode) { +function validateZipCodeRegex(zipCode) { return /^\d{5}(-\d{4})?$/.test(zipCode); } @@ -450,7 +450,7 @@ async function validateStep(step) { // ZIP code validation const zipCode = document.getElementById('card-zip').value; - if (!validateZipCode(zipCode)) { + if (!validateZipCodeRegex(zipCode)) { isValid = false; showError('Please enter a valid ZIP code', 'card-zip', step); return isValid; diff --git a/src/controllers/va/vaAuth/vaLogin.controller.js b/src/controllers/va/vaAuth/vaLogin.controller.js index 7e00699..cff77bc 100644 --- a/src/controllers/va/vaAuth/vaLogin.controller.js +++ b/src/controllers/va/vaAuth/vaLogin.controller.js @@ -42,54 +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 { - // 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 { + 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, + // }; } catch (error) { console.error("Error closing previous session:", error);