Fixed Bank details update route
This commit is contained in:
parent
1cdb7a1351
commit
7ecf177467
|
|
@ -2226,3 +2226,12 @@ tr[data-vaid]:hover {
|
||||||
background-color: rgba(16, 185, 129, 0.1);
|
background-color: rgba(16, 185, 129, 0.1);
|
||||||
color: var(--color-success);
|
color: var(--color-success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-error {
|
||||||
|
border: 1px solid var(--error-color) !important;
|
||||||
|
background-color: rgba(220, 38, 38, 0.05) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] .field-error {
|
||||||
|
background-color: rgba(220, 38, 38, 0.1) !important;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
import { ClientModel } from "../../../models/vaModel.js";
|
||||||
|
import authFetch from "../../../utils/authFetch.js";
|
||||||
|
|
||||||
|
async function update_client_bank_details(req, res) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const clientId = req.body.clientId;
|
||||||
|
const clientEmail = req.body.clientEmail;
|
||||||
|
const payload = req.body || {};
|
||||||
|
const { userDetails } = payload;
|
||||||
|
|
||||||
|
const client = await ClientModel.findById(clientId);
|
||||||
|
if (!client) {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
message: "Client not found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userDetails) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: "Missing userDetails in request body"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
userDetails._id = clientId; // Ensure the _id is set to clientId
|
||||||
|
userDetails.email = clientEmail; // Ensure the email is set to clientEmail
|
||||||
|
|
||||||
|
// console.log("Final userDetails to update:", userDetails);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}/services/apexrest/docva/api/client`;
|
||||||
|
|
||||||
|
const response = await authFetch(salesforceUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ userDetails })
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: "Client bank details updated and synced with Salesforce successfully",
|
||||||
|
data: 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) {
|
||||||
|
if (error.message === "Client not found") {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: "Internal Server Error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { update_client_bank_details };
|
||||||
|
|
@ -16,6 +16,7 @@ import { client_logout_callback } from "../../controllers/client/dashboard/clien
|
||||||
import { va_tips_delete, va_tips_get, va_tips_manage_function, va_tips_update } from "../../controllers/va/vaTips/vaTipsManage.controller.js";
|
import { va_tips_delete, va_tips_get, va_tips_manage_function, va_tips_update } from "../../controllers/va/vaTips/vaTipsManage.controller.js";
|
||||||
import { clientDashboardGetVaLogsController } from "../../controllers/client/dashboard/clientDashboardGetVaLogs.controller.js";
|
import { clientDashboardGetVaLogsController } from "../../controllers/client/dashboard/clientDashboardGetVaLogs.controller.js";
|
||||||
import { va_credits_get } from "../../controllers/client/dashboard/clientDashboardCredits.controller.js";
|
import { va_credits_get } from "../../controllers/client/dashboard/clientDashboardCredits.controller.js";
|
||||||
|
import { update_client_bank_details } from "../../controllers/client/dashboard/clientUpdateBankDetails.controller.js";
|
||||||
|
|
||||||
// clients routes
|
// clients routes
|
||||||
clientRoutes.post("/register", va_register_client); // Register a new VA
|
clientRoutes.post("/register", va_register_client); // Register a new VA
|
||||||
|
|
@ -43,6 +44,7 @@ clientRoutes.post("/dashboard/va-report", clientAuthValidator, client_dashboard_
|
||||||
clientRoutes.get("/dashboard-projects", clientAuthValidator, client_dashboard_projects); // VA Clients Projects Callback
|
clientRoutes.get("/dashboard-projects", clientAuthValidator, client_dashboard_projects); // VA Clients Projects Callback
|
||||||
clientRoutes.get("/profile", clientAuthValidator, get_client_dashboard_profile);
|
clientRoutes.get("/profile", clientAuthValidator, get_client_dashboard_profile);
|
||||||
clientRoutes.patch("/profile", clientAuthValidator, update_client_password);
|
clientRoutes.patch("/profile", clientAuthValidator, update_client_password);
|
||||||
|
clientRoutes.post("/profile", clientAuthValidator, update_client_bank_details);
|
||||||
clientRoutes.patch("/:clientId", update_client);
|
clientRoutes.patch("/:clientId", update_client);
|
||||||
clientRoutes.delete("/:clientId", delete_client);
|
clientRoutes.delete("/:clientId", delete_client);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue