From cd1345312110c37bef57068c8b303b3df47fec73 Mon Sep 17 00:00:00 2001 From: robbond Date: Fri, 13 Mar 2026 06:41:47 +0000 Subject: [PATCH] refactor(actions): phase 5 extract account and case direct services --- actions/services/accountDirectService.js | 145 +++++++++ actions/services/accountService.js | 2 +- actions/services/caseDirectService.js | 362 +++++++++++++++++++++++ actions/services/caseService.js | 2 +- 4 files changed, 509 insertions(+), 2 deletions(-) create mode 100644 actions/services/accountDirectService.js create mode 100644 actions/services/caseDirectService.js diff --git a/actions/services/accountDirectService.js b/actions/services/accountDirectService.js new file mode 100644 index 00000000..5f719fd2 --- /dev/null +++ b/actions/services/accountDirectService.js @@ -0,0 +1,145 @@ +import axios from "axios"; +import { BASE_URL } from "../core/env"; +import { consoleLogger } from "../core/logger"; +import { hashAPIPath } from "../core/hash"; + +export const getPersonalAccount = (contactid) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getpersonalaccount_api?contactid=" + + contactid + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const getLogin = (emailAddress, pwd) => { + return axios + .get( + "/api/endpoint/getlogin_api?emailAddress=" + + emailAddress + + "&pwd=" + + pwd + ) + .then((res) => res.data) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const updatePassword = (contactId, newpassword) => { + var queryUrl = "/api/endpoint/updateaccount_api?contactId=" + contactId; + var data = { "pinswg_custom_password": newpassword }; + var config = { + method: "post", + url: queryUrl, + data: data + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const updateAccount = async (contactId, updateBody, ssr) => { + var queryUrl = + (ssr ? BASE_URL : "") + + "/api/endpoint/updateaccount_api?contactId=" + + contactId; + var data = updateBody; + var config = { + method: "post", + url: queryUrl, + data: data + }; + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const createAccount = (formValues) => { + var data = formValues; + var queryUrl = "/api/endpoint/createaccount_api"; + var config = { + method: "post", + url: queryUrl, + data: data + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const getEmailAccountCheck = (emailAddress) => { + return axios + .get( + "/api/endpoint/getemailaccountcheck_api?emailAddress=" + + emailAddress + ) + .then((res) => res.data) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const getPortalLogin = async (emailAddress) => { + var queryUrl = + "/api/endpoint/getportallogin_api?emailAddress=" + emailAddress; + + return axios + .get(BASE_URL + queryUrl + hashAPIPath(queryUrl)) + .then((res) => res.data) + .catch((error) => { + consoleLogger(error); + + return JSON.stringify(error); + }); +}; + +export const getPortalLoginProxy = async (emailAddress) => { + var queryUrl = + "/api/endpoint/getportalloginproxy_api?emailAddress=" + emailAddress; + + return axios + .get(queryUrl) + .then((res) => res.data) + .catch((error) => { + consoleLogger(error); + + return JSON.stringify(error); + }); +}; + +export const getPreferredLanguage = async (email) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getpreferredlanguage_api?emailAddress=" + + email + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; diff --git a/actions/services/accountService.js b/actions/services/accountService.js index b0287211..1cf7f7aa 100644 --- a/actions/services/accountService.js +++ b/actions/services/accountService.js @@ -8,7 +8,7 @@ import { getPortalLogin, getPortalLoginProxy, getPreferredLanguage -} from "./legacyActionsService"; +} from "./accountDirectService"; export { getPersonalAccount, diff --git a/actions/services/caseDirectService.js b/actions/services/caseDirectService.js new file mode 100644 index 00000000..5e1c5f8b --- /dev/null +++ b/actions/services/caseDirectService.js @@ -0,0 +1,362 @@ +import axios from "axios"; +import { BASE_URL } from "../core/env"; +import { consoleLogger } from "../core/logger"; + +export const getCaseMessage = (searchString) => { + return axios + .get(BASE_URL + "/api/endpoint/getcasemessage_api?id=" + searchString) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getIncidentbyID = (searchString) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getincidentbyid_api?searchString=" + + searchString + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getIsPublishedbyID = (searchString) => { + return axios + .get( + "/api/endpoint/getispublishedbyid_api?searchString=" + searchString + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getPartSavedAppeal = (searchString) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getpartsavedappeal_api?searchString=" + + searchString + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getSIPSEvents = async (caseid) => { + return axios + .get(BASE_URL + "/api/endpoint/getsipsevents_api?caseid=" + caseid) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getSIPSMedia = async (caseid) => { + return axios + .get(BASE_URL + "/api/endpoint/getsipsmedia_api?caseid=" + caseid) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getAppealID = ( + caseReference, + updateFormCollection, + primaryAttribute +) => { + return axios + .get( + "/api/endpoint/getappealid_api?updateFormCollection=" + + updateFormCollection + + "&primaryAttribute=" + + primaryAttribute + + "&caseReference=" + + caseReference + ) + .then((res) => { + const result = Object.entries(res.data.value[0]).filter( + ([key]) => !key.startsWith("_") + )[0][1]; + var appealID = result; + return appealID; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const createNewCase = ( + appealTypeId, + lpaID, + contactid, + createBody, + containerName +) => { + appealTypeId = parseInt(appealTypeId); + + var data = createBody; + + var queryUrl = + "/api/endpoint/createcase_api?appealTypeId=" + + appealTypeId + + "&lpaID=" + + lpaID + + "&contactid=" + + contactid + + "&containername=" + + containerName; + + var config = { + method: "post", + url: BASE_URL + queryUrl, + data: data + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const createNewCaseBlob = ( + appealTypeId, + lpaID, + contactid, + createBody, + containerName, + lpaName +) => { + appealTypeId = parseInt(appealTypeId); + + var data = createBody; + + data.pinswg_lpaname = lpaName; + data.createdon = new Date(); + + var queryUrl = + "/api/file/createcase_api?appealTypeId=" + + appealTypeId + + "&lpaID=" + + lpaID + + "&contactid=" + + contactid + + "&containername=" + + containerName; + + var config = { + method: "post", + url: queryUrl, + data: data + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const updateCase = async ( + incidentId, + updateBody, + updateFormCollection, + primaryAttribute, + caseReference +) => { + var data = updateBody; + + var appealObj = await getAppealID( + caseReference, + updateFormCollection, + primaryAttribute + ); + + var queryUrl = + "/api/endpoint/updatecase_api?updateFormCollection=" + + updateFormCollection + + "&appealObj=" + + appealObj; + + var config = { + method: "post", + url: queryUrl, + data: updateBody + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const updateCaseBlob = async ( + incidentId, + updateBody, + updateFormCollection, + primaryAttribute, + caseReference +) => { + var data = updateBody; + + var appealObj = await getAppealID( + caseReference, + updateFormCollection, + primaryAttribute + ); + + var queryUrl = + "/api/file/updatecase_api?updateFormCollection=" + + updateFormCollection + + "&appealObj=" + + appealObj; + + var config = { + method: "post", + url: queryUrl, + data: updateBody + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const patchCase = async (incidentid) => { + var queryUrl = "/api/endpoint/patchcase_api?incidentid=" + incidentid; + var config = { + method: "get", + url: queryUrl + }; + + return axios(config) + .then((res) => { + return res.data; + }) + .catch((error) => { + //console.log("this error:", error); + }); +}; + +export const getCase = (incidentID) => { + return axios + .get(BASE_URL + "/api/endpoint/getcase_api?incidentID=" + incidentID) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const getCaseByID = (incidentID) => { + return axios + .get( + BASE_URL + "/api/endpoint/getcasebyid_api?incidentID=" + incidentID + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const getAppealPDFDocs = (incidentID) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getappealpdfdocuments_api?incidentid=" + + incidentID + ) + .then((res) => res.data) + .catch((error) => { + consoleLogger(error); + }); +}; + +export const getAppealPDFDocument = async (incidentid) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getappealpdfdocuments_api?incidentid=" + + incidentid + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + consoleLogger(error); + return error.response; + }); +}; + +export const getPortalModuleDetails = async (appealType, caseReference) => { + var config = { + method: "get", + url: + BASE_URL + + "/api/endpoint/getportalmoduledetails_api?appealType=" + + appealType + + "&caseReference=" + + encodeURI(caseReference) + }; + + try { + const res = await axios(config); + return res.data; + } catch (error) { + console.log("error case ref:", caseReference); + consoleLogger(error); + } +}; + +export const getPortalModuleDetailsProxy = (appealType, caseReference) => { + return axios + .get( + "/api/endpoint/getportalmoduledetailsproxy_api?appealType=" + + appealType + + "&caseReference=" + + caseReference.replace(/\'/g, "''") + ) + .then((res) => res.data) + .catch((error) => { + consoleLogger(error); + }); +}; diff --git a/actions/services/caseService.js b/actions/services/caseService.js index a5f682e8..ca19d922 100644 --- a/actions/services/caseService.js +++ b/actions/services/caseService.js @@ -17,7 +17,7 @@ import { getIsPublishedbyID, getPortalModuleDetails, getPortalModuleDetailsProxy -} from "./legacyActionsService"; +} from "./caseDirectService"; export { getCaseMessage,