From cbb742ac77e9e9e17f47c5cc280186c6759e732f Mon Sep 17 00:00:00 2001 From: Alessandro Falezza Date: Tue, 9 Aug 2022 17:47:01 +0200 Subject: [PATCH] Move basePath and mock server option to env --- .env | 1 + .env.development | 1 + .env.docker | 16 +++--- .env.gh-pages | 3 +- .env.staging | 3 +- .env.test | 1 + docker-compose.yaml | 5 +- docker/Dockerfile.frontend | 9 ++-- src/index.tsx | 3 +- src/libraries/apiUtils/configuration.ts | 13 +++++ src/state/admissionTypes/actions.ts | 10 ++-- src/state/admissions/actions.ts | 28 +++++------ src/state/ageTypes/actions.ts | 12 ++--- src/state/bills/actions.ts | 67 ++++++++++++------------- src/state/dischargeTypes/actions.ts | 10 ++-- src/state/diseaseTypes/actions.ts | 12 ++--- src/state/diseases/actions.ts | 20 +++----- src/state/examTypes/actions.ts | 12 ++--- src/state/examinations/actions.ts | 5 +- src/state/exams/actions.ts | 11 ++-- src/state/laboratories/actions.ts | 35 ++++++------- src/state/main/actions.ts | 9 ++-- src/state/medicals/actions.ts | 7 +-- src/state/opds/actions.ts | 41 ++++++--------- src/state/operations/actions.ts | 7 ++- src/state/patients/actions.ts | 14 ++---- src/state/prices/actions.ts | 21 ++++---- src/state/summary/actions.ts | 20 +++----- src/state/therapies/actions.ts | 7 +-- src/state/visits/actions.ts | 16 +++--- src/state/ward/actions.ts | 8 ++- 31 files changed, 181 insertions(+), 246 deletions(-) create mode 100644 .env create mode 100644 .env.development create mode 100644 .env.test create mode 100644 src/libraries/apiUtils/configuration.ts diff --git a/.env b/.env new file mode 100644 index 000000000..80bea08df --- /dev/null +++ b/.env @@ -0,0 +1 @@ +REACT_APP_USE_MOCK_API= \ No newline at end of file diff --git a/.env.development b/.env.development new file mode 100644 index 000000000..1845c394b --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +REACT_APP_USE_MOCK_API=true \ No newline at end of file diff --git a/.env.docker b/.env.docker index b6af7ce39..b603f260e 100644 --- a/.env.docker +++ b/.env.docker @@ -1,3 +1,9 @@ +GITHUB_ORG=intesys +OH_CORE_BRANCH=staging3Test +OH_API_BRANCH=staging3Test +API_VERSION=0.0.1 +API_PORT:8080 + MYSQL_TAG=8.0.25 MYSQL_DATABASE=oh MYSQL_PORT=3306 @@ -5,10 +11,6 @@ MYSQL_ROOT_PASSWORD=root MYSQL_USER=isf MYSQL_PASSWORD=isf123 -GITHUB_ORG=intesys -OH_CORE_BRANCH=staging3Test -OH_API_BRANCH=staging3Test -API_VERSION=0.0.1 -API_PORT:8080 - -NODE_ENV=development \ No newline at end of file +PUBLIC_URL=/ +REACT_APP_USE_MOCK_API= +REACT_APP_BASE_PATH=http://localhost:8080/oh-api \ No newline at end of file diff --git a/.env.gh-pages b/.env.gh-pages index 4a10dffb5..48699f4c0 100644 --- a/.env.gh-pages +++ b/.env.gh-pages @@ -1 +1,2 @@ -PUBLIC_URL=/openhospital-ui \ No newline at end of file +PUBLIC_URL=/openhospital-ui +REACT_APP_USE_MOCK_API= \ No newline at end of file diff --git a/.env.staging b/.env.staging index b5dcf5627..16310c10d 100644 --- a/.env.staging +++ b/.env.staging @@ -1 +1,2 @@ -PUBLIC_URL=/oh20 \ No newline at end of file +PUBLIC_URL=/oh20 +REACT_APP_USE_MOCK_API= \ No newline at end of file diff --git a/.env.test b/.env.test new file mode 100644 index 000000000..1845c394b --- /dev/null +++ b/.env.test @@ -0,0 +1 @@ +REACT_APP_USE_MOCK_API=true \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 88a157a73..962b1f783 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,8 +5,8 @@ services: build: context: ./ dockerfile: ./docker/Dockerfile.frontend - args: - PUBLIC_URL: / + env_file: + - .env.docker ports: - 3000:3000 volumes: @@ -19,6 +19,7 @@ services: networks: - openhospital stdin_open: true + backend: build: context: ./docker diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend index dfb0db448..a34120f68 100644 --- a/docker/Dockerfile.frontend +++ b/docker/Dockerfile.frontend @@ -1,15 +1,12 @@ FROM node:lts -ARG PUBLIC_URL - -ENV NODE_ENV=development +ENV PUBLIC_URL=/ +ENV REACT_APP_USE_MOCK_API= +ENV REACT_APP_BASE_PATH=/ VOLUME /oh - WORKDIR /oh - COPY ../package*.json /oh - RUN npm ci --legacy-peer-deps CMD npm start diff --git a/src/index.tsx b/src/index.tsx index 677116af7..835a1d41d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -31,7 +31,8 @@ import diseaseTypes from "./state/diseaseTypes/reducer"; import examTypes from "./state/examTypes/reducer"; import ageTypes from "./state/ageTypes/reducer"; -if (process.env.NODE_ENV === "development") { +if (process.env.REACT_APP_USE_MOCK_API) { + console.log("Using mocked api"); makeServer(); } diff --git a/src/libraries/apiUtils/configuration.ts b/src/libraries/apiUtils/configuration.ts new file mode 100644 index 000000000..c6a788635 --- /dev/null +++ b/src/libraries/apiUtils/configuration.ts @@ -0,0 +1,13 @@ +import { BASE_PATH, Configuration } from "../../generated"; +import { applyTokenMiddleware } from "./applyTokenMiddleware"; + +const basePath = process.env.REACT_APP_BASE_PATH || BASE_PATH; + +export const customConfiguration = (authenticated = true) => { + return authenticated + ? new Configuration({ + basePath, + middleware: [applyTokenMiddleware], + }) + : new Configuration({ basePath }); +}; diff --git a/src/state/admissionTypes/actions.ts b/src/state/admissionTypes/actions.ts index 820147b51..0232d7e74 100644 --- a/src/state/admissionTypes/actions.ts +++ b/src/state/admissionTypes/actions.ts @@ -1,10 +1,6 @@ import { Dispatch } from "redux"; -import { - Configuration, - AdmissionDTO, - AdmissionTypeControllerApi, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { AdmissionDTO, AdmissionTypeControllerApi } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_ADMISSIONTYPE_FAIL, @@ -14,7 +10,7 @@ import { } from "./consts"; const admissionTypeControllerApi = new AdmissionTypeControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const getAdmissionTypes = diff --git a/src/state/admissions/actions.ts b/src/state/admissions/actions.ts index c0898352d..9b8fa62e9 100644 --- a/src/state/admissions/actions.ts +++ b/src/state/admissions/actions.ts @@ -1,37 +1,33 @@ import { isEmpty } from "lodash"; import { Dispatch } from "redux"; -import { - Configuration, - AdmissionDTO, - AdmissionControllerApi, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { AdmissionControllerApi, AdmissionDTO } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { CREATE_ADMISSION_FAIL, CREATE_ADMISSION_LOADING, CREATE_ADMISSION_RESET, CREATE_ADMISSION_SUCCESS, - UPDATE_ADMISSION_FAIL, - UPDATE_ADMISSION_LOADING, - UPDATE_ADMISSION_RESET, - UPDATE_ADMISSION_SUCCESS, + DISCHARGE_PATIENT_FAIL, + DISCHARGE_PATIENT_LOADING, + DISCHARGE_PATIENT_RESET, + DISCHARGE_PATIENT_SUCCESS, GET_ADMISSION_FAIL, GET_ADMISSION_LOADING, GET_ADMISSION_SUCCESS, GET_ADMISSION_SUCCESS_EMPTY, + GET_CURRENTADMISSION_EMPTY, GET_CURRENTADMISSION_FAIL, GET_CURRENTADMISSION_LOADING, GET_CURRENTADMISSION_SUCCESS, - GET_CURRENTADMISSION_EMPTY, - DISCHARGE_PATIENT_LOADING, - DISCHARGE_PATIENT_SUCCESS, - DISCHARGE_PATIENT_FAIL, - DISCHARGE_PATIENT_RESET, + UPDATE_ADMISSION_FAIL, + UPDATE_ADMISSION_LOADING, + UPDATE_ADMISSION_RESET, + UPDATE_ADMISSION_SUCCESS, } from "./consts"; const admissionControllerApi = new AdmissionControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const createAdmission = diff --git a/src/state/ageTypes/actions.ts b/src/state/ageTypes/actions.ts index defde4547..df1fb5694 100644 --- a/src/state/ageTypes/actions.ts +++ b/src/state/ageTypes/actions.ts @@ -1,10 +1,6 @@ import { Dispatch } from "redux"; -import { - Configuration, - AdmissionDTO, - AgeTypeControllerApi, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { AdmissionDTO, AgeTypeControllerApi } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_AGETYPES_FAIL, @@ -13,9 +9,7 @@ import { GET_AGETYPES_SUCCESS_EMPTY, } from "./consts"; -const ageTypeControllerApi = new AgeTypeControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const ageTypeControllerApi = new AgeTypeControllerApi(customConfiguration()); export const getAgeTypes = () => diff --git a/src/state/bills/actions.ts b/src/state/bills/actions.ts index 833f95745..da14cb1d2 100644 --- a/src/state/bills/actions.ts +++ b/src/state/bills/actions.ts @@ -1,59 +1,56 @@ -import { Dispatch } from "redux"; -import { map, catchError, switchMap } from "rxjs/operators"; -import { of, Observable, forkJoin } from "rxjs"; import isEmpty from "lodash.isempty"; +import { Dispatch } from "redux"; +import { forkJoin, Observable, of } from "rxjs"; +import { catchError, map, switchMap } from "rxjs/operators"; +import { TFilterValues } from "../../components/accessories/billTable/types"; import { - Configuration, BillControllerApi, BillDTO, - FullBillDTO, BillItemsDTO, BillPaymentsDTO, + FullBillDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { + CLOSE_BILL_FAIL, + CLOSE_BILL_LOADING, + CLOSE_BILL_RESET, + CLOSE_BILL_SUCCESS, + DELETE_BILL_FAIL, + DELETE_BILL_LOADING, + DELETE_BILL_RESET, + DELETE_BILL_SUCCESS, + EDIT_BILL_FAIL, + EDIT_BILL_LOADING, + EDIT_BILL_RESET, + EDIT_BILL_SUCCESS, + GET_BILL_FAIL, + GET_BILL_LOADING, + GET_BILL_SUCCESS, NEW_BILL_FAIL, NEW_BILL_LOADING, - NEW_BILL_SUCCESS, NEW_BILL_RESET, + NEW_BILL_SUCCESS, + PENDING_BILL_FAIL, + PENDING_BILL_LOADING, + PENDING_BILL_SUCCESS, + SEARCH_BILLS_BY_YEAR_FAIL, + SEARCH_BILLS_BY_YEAR_LOADING, + SEARCH_BILLS_BY_YEAR_SUCCESS, SEARCH_BILL_FAIL, SEARCH_BILL_LOADING, SEARCH_BILL_SUCCESS, - GET_BILL_LOADING, - GET_BILL_SUCCESS, - GET_BILL_FAIL, - PENDING_BILL_SUCCESS, - PENDING_BILL_FAIL, - PENDING_BILL_LOADING, - SEARCH_PAYMENTS_SUCCESS, SEARCH_PAYMENTS_FAIL, SEARCH_PAYMENTS_LOADING, - DELETE_BILL_FAIL, - DELETE_BILL_LOADING, - DELETE_BILL_SUCCESS, - DELETE_BILL_RESET, - EDIT_BILL_LOADING, - EDIT_BILL_SUCCESS, - EDIT_BILL_FAIL, - EDIT_BILL_RESET, - CLOSE_BILL_FAIL, - CLOSE_BILL_SUCCESS, - CLOSE_BILL_LOADING, - CLOSE_BILL_RESET, - UPDATE_BILL_LOADING, - UPDATE_BILL_SUCCESS, + SEARCH_PAYMENTS_SUCCESS, UPDATE_BILL_FAIL, + UPDATE_BILL_LOADING, UPDATE_BILL_RESET, - SEARCH_BILLS_BY_YEAR_LOADING, - SEARCH_BILLS_BY_YEAR_SUCCESS, - SEARCH_BILLS_BY_YEAR_FAIL, + UPDATE_BILL_SUCCESS, } from "./consts"; -import { TFilterValues } from "../../components/accessories/billTable/types"; -const billControllerApi = new BillControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const billControllerApi = new BillControllerApi(customConfiguration()); export const newBill = (newBillDto: FullBillDTO) => diff --git a/src/state/dischargeTypes/actions.ts b/src/state/dischargeTypes/actions.ts index a7f6e26de..c7279b772 100644 --- a/src/state/dischargeTypes/actions.ts +++ b/src/state/dischargeTypes/actions.ts @@ -1,10 +1,6 @@ import { Dispatch } from "redux"; -import { - Configuration, - AdmissionDTO, - DischargeTypeControllerApi, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { AdmissionDTO, DischargeTypeControllerApi } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_DISCHARGETYPE_FAIL, @@ -14,7 +10,7 @@ import { } from "./consts"; const dischargeTypeControllerApi = new DischargeTypeControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const getDischargeTypes = diff --git a/src/state/diseaseTypes/actions.ts b/src/state/diseaseTypes/actions.ts index d2f01c907..bffb6a81a 100644 --- a/src/state/diseaseTypes/actions.ts +++ b/src/state/diseaseTypes/actions.ts @@ -1,13 +1,7 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; -import { - Configuration, - DiseaseControllerApi, - DiseaseDTO, - DiseaseTypeControllerApi, - DiseaseTypeDTO, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { DiseaseTypeControllerApi, DiseaseTypeDTO } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_DISEASETYPE_FAIL, @@ -16,7 +10,7 @@ import { } from "./consts"; const desaseTypeControllerApi = new DiseaseTypeControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const getDiseaseTypes = diff --git a/src/state/diseases/actions.ts b/src/state/diseases/actions.ts index 41b7a1e25..9cf6c645f 100644 --- a/src/state/diseases/actions.ts +++ b/src/state/diseases/actions.ts @@ -1,27 +1,21 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; -import { - Configuration, - DiseaseControllerApi, - DiseaseDTO, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { DiseaseControllerApi, DiseaseDTO } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { - GET_DISEASE_FAIL, - GET_DISEASE_LOADING, - GET_DISEASE_SUCCESS, GET_DISEASEIPDIN_FAIL, GET_DISEASEIPDIN_LOADING, GET_DISEASEIPDIN_SUCCESS, GET_DISEASEIPDOUT_FAIL, - GET_DISEASEIPDOUT_SUCCESS, GET_DISEASEIPDOUT_LOADING, + GET_DISEASEIPDOUT_SUCCESS, + GET_DISEASE_FAIL, + GET_DISEASE_LOADING, + GET_DISEASE_SUCCESS, } from "./consts"; -const desaseControllerApi = new DiseaseControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const desaseControllerApi = new DiseaseControllerApi(customConfiguration()); export const getDiseasesOpd = () => diff --git a/src/state/examTypes/actions.ts b/src/state/examTypes/actions.ts index 367f88647..6eded62df 100644 --- a/src/state/examTypes/actions.ts +++ b/src/state/examTypes/actions.ts @@ -1,13 +1,7 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; -import { - Configuration, - ExamControllerApi, - ExamDTO, - ExamTypeControllerApi, - ExamTypeDTO, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { ExamTypeControllerApi, ExamTypeDTO } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_EXAMTYPE_FAIL, @@ -16,7 +10,7 @@ import { } from "./consts"; const desaseTypeControllerApi = new ExamTypeControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const getExamTypes = diff --git a/src/state/examinations/actions.ts b/src/state/examinations/actions.ts index 546fe5dc0..87acb971b 100644 --- a/src/state/examinations/actions.ts +++ b/src/state/examinations/actions.ts @@ -1,10 +1,9 @@ import { Dispatch } from "redux"; import { - Configuration, ExaminationControllerApi, PatientExaminationDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { CREATE_EXAMINATION_FAIL, @@ -24,7 +23,7 @@ import { } from "./consts"; const examinationControllerApi = new ExaminationControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const createExamination = diff --git a/src/state/exams/actions.ts b/src/state/exams/actions.ts index e0020da97..77fbb73b3 100644 --- a/src/state/exams/actions.ts +++ b/src/state/exams/actions.ts @@ -1,13 +1,12 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; import { - Configuration, ExamControllerApi, ExamDTO, ExamRowControllerApi, ExamRowDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_EXAMROW_FAIL, @@ -18,13 +17,9 @@ import { GET_EXAM_SUCCESS, } from "./consts"; -const examControllerApi = new ExamControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const examControllerApi = new ExamControllerApi(customConfiguration()); -const examRowControllerApi = new ExamRowControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const examRowControllerApi = new ExamRowControllerApi(customConfiguration()); export const getExams = () => diff --git a/src/state/laboratories/actions.ts b/src/state/laboratories/actions.ts index 272c4b5c7..361db3eb0 100644 --- a/src/state/laboratories/actions.ts +++ b/src/state/laboratories/actions.ts @@ -1,12 +1,11 @@ import moment from "moment"; import { Dispatch } from "redux"; import { - Configuration, LaboratoryControllerApi, LaboratoryDTO, LabWithRowsDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { CREATE_LAB_FAIL, @@ -19,34 +18,32 @@ import { DELETE_LAB_SUCCESS, GET_LABS_FAIL, GET_LABS_LOADING, + GET_LABS_RESET, GET_LABS_SUCCESS, GET_LABS_SUCCESS_EMPTY, + GET_LABWROW_FAIL, + GET_LABWROW_LOADING, + GET_LABWROW_RESET, + GET_LABWROW_SUCCESS, + GET_LAB_FAIL, + GET_LAB_LOADING, + GET_LAB_RESET, + GET_LAB_SUCCESS, GET_MATERIALS_FAIL, GET_MATERIALS_LOADING, GET_MATERIALS_SUCCESS, + SEARCH_LAB_FAIL, + SEARCH_LAB_LOADING, + SEARCH_LAB_RESET, + SEARCH_LAB_SUCCESS, + SEARCH_LAB_SUCCESS_EMPTY, UPDATE_LAB_FAIL, UPDATE_LAB_LOADING, UPDATE_LAB_RESET, UPDATE_LAB_SUCCESS, - SEARCH_LAB_LOADING, - SEARCH_LAB_SUCCESS, - SEARCH_LAB_FAIL, - SEARCH_LAB_SUCCESS_EMPTY, - GET_LABS_RESET, - SEARCH_LAB_RESET, - GET_LAB_FAIL, - GET_LAB_LOADING, - GET_LAB_SUCCESS, - GET_LAB_RESET, - GET_LABWROW_RESET, - GET_LABWROW_FAIL, - GET_LABWROW_LOADING, - GET_LABWROW_SUCCESS, } from "./consts"; -const labControllerApi = new LaboratoryControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const labControllerApi = new LaboratoryControllerApi(customConfiguration()); export const createLab = (labWithRowsDTO: LabWithRowsDTO) => diff --git a/src/state/main/actions.ts b/src/state/main/actions.ts index e60176066..c390c898e 100644 --- a/src/state/main/actions.ts +++ b/src/state/main/actions.ts @@ -2,14 +2,13 @@ import { Dispatch } from "redux"; import { concat } from "rxjs"; import { tap, toArray } from "rxjs/operators"; import { - Configuration, LoginControllerApi, LoginRequest, LoginResponse, UserControllerApi, UserProfileDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { saveAuthenticationDataToSession } from "../../libraries/authUtils/saveAuthenticationDataToSession"; import { savePermissionDataToSession } from "../../libraries/authUtils/savePermissionDataToSession"; import { SessionStorage } from "../../libraries/storage/storage"; @@ -24,10 +23,8 @@ import { } from "./consts"; import { IAuthentication } from "./types"; -const api = new LoginControllerApi(new Configuration()); -const usersApi = new UserControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const api = new LoginControllerApi(customConfiguration(false)); +const usersApi = new UserControllerApi(customConfiguration()); export const setAuthenticationSuccess = ( payload: IAuthentication diff --git a/src/state/medicals/actions.ts b/src/state/medicals/actions.ts index 0e0e0bb55..61aff3aa8 100644 --- a/src/state/medicals/actions.ts +++ b/src/state/medicals/actions.ts @@ -1,12 +1,11 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; import { - Configuration, GetMedicalsUsingGETSortByEnum, MedicalControllerApi, MedicalDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_MEDICAL_FAIL, @@ -14,9 +13,7 @@ import { GET_MEDICAL_SUCCESS, } from "./consts"; -const medicalControllerApi = new MedicalControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const medicalControllerApi = new MedicalControllerApi(customConfiguration()); export const getMedicals = () => diff --git a/src/state/opds/actions.ts b/src/state/opds/actions.ts index 9a3a82708..eb26bde36 100644 --- a/src/state/opds/actions.ts +++ b/src/state/opds/actions.ts @@ -1,43 +1,34 @@ import moment from "moment"; import { Dispatch } from "redux"; -import { TFilterValues } from "../../components/accessories/opds/filter/types"; -import { - Configuration, - DiseaseDTO, - OpdControllerApi, - OpdDTO, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; -import { opdDataFormatter } from "../../libraries/formatUtils/dataFormatting"; +import { OpdControllerApi, OpdDTO } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { - CREATE_OPD_RESET, + CREATE_OPD_FAIL, CREATE_OPD_LOADING, + CREATE_OPD_RESET, CREATE_OPD_SUCCESS, - CREATE_OPD_FAIL, + DELETE_OPD_FAIL, + DELETE_OPD_LOADING, + DELETE_OPD_RESET, + DELETE_OPD_SUCCESS, GET_OPD_FAIL, GET_OPD_LOADING, + GET_OPD_RESET, GET_OPD_SUCCESS, GET_OPD_SUCCESS_EMPTY, - UPDATE_OPD_LOADING, - UPDATE_OPD_SUCCESS, - UPDATE_OPD_FAIL, - UPDATE_OPD_RESET, - DELETE_OPD_LOADING, - DELETE_OPD_SUCCESS, - DELETE_OPD_FAIL, - DELETE_OPD_RESET, + SEARCH_OPD_FAIL, SEARCH_OPD_LOADING, + SEARCH_OPD_RESET, SEARCH_OPD_SUCCESS, - SEARCH_OPD_FAIL, SEARCH_OPD_SUCCESS_EMPTY, - GET_OPD_RESET, - SEARCH_OPD_RESET, + UPDATE_OPD_FAIL, + UPDATE_OPD_LOADING, + UPDATE_OPD_RESET, + UPDATE_OPD_SUCCESS, } from "./consts"; -const opdControllerApi = new OpdControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const opdControllerApi = new OpdControllerApi(customConfiguration()); export const createOpd = (opdDTO: OpdDTO) => diff --git a/src/state/operations/actions.ts b/src/state/operations/actions.ts index bb3e04908..01fd75e24 100644 --- a/src/state/operations/actions.ts +++ b/src/state/operations/actions.ts @@ -1,12 +1,11 @@ import { isEmpty } from "lodash"; import { Dispatch } from "redux"; import { - Configuration, - OperationRowDTO, OperationControllerApi, OperationDTO, + OperationRowDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { CREATE_OPERATIONROW_FAIL, @@ -31,7 +30,7 @@ import { } from "./consts"; const operationControllerApi = new OperationControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const createOperationRow = diff --git a/src/state/patients/actions.ts b/src/state/patients/actions.ts index dfaf33a38..e8fd864f1 100644 --- a/src/state/patients/actions.ts +++ b/src/state/patients/actions.ts @@ -1,12 +1,8 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; import { TValues } from "../../components/activities/searchPatientActivity/types"; -import { - Configuration, - PatientControllerApi, - PatientDTO, -} from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { PatientControllerApi, PatientDTO } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { CREATE_PATIENT_FAIL, @@ -19,15 +15,13 @@ import { SEARCH_PATIENT_FAIL, SEARCH_PATIENT_LOADING, SEARCH_PATIENT_SUCCESS, - UPDATE_PATIENT_LOADING, UPDATE_PATIENT_FAIL, + UPDATE_PATIENT_LOADING, UPDATE_PATIENT_RESET, UPDATE_PATIENT_SUCCESS, } from "./consts"; -const patientControllerApi = new PatientControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const patientControllerApi = new PatientControllerApi(customConfiguration()); export const createPatient = (newPatient: PatientDTO) => diff --git a/src/state/prices/actions.ts b/src/state/prices/actions.ts index 2013728b0..c5d9dcf07 100644 --- a/src/state/prices/actions.ts +++ b/src/state/prices/actions.ts @@ -1,22 +1,19 @@ -import { Dispatch } from "redux"; import isEmpty from "lodash.isempty"; -import { Configuration } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { Dispatch } from "redux"; +import { PriceListControllerApi } from "../../generated/apis/PriceListControllerApi"; +import { PriceDTO } from "../../generated/models/PriceDTO"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { - GET_PRICE_LOADING, - GET_PRICE_SUCCESS, - GET_PRICE_FAIL, + GET_PRICELISTS_FAIL, GET_PRICELISTS_LOADING, GET_PRICELISTS_SUCCESS, - GET_PRICELISTS_FAIL, + GET_PRICE_FAIL, + GET_PRICE_LOADING, + GET_PRICE_SUCCESS, } from "./consts"; -import { PriceListControllerApi } from "../../generated/apis/PriceListControllerApi"; -import { PriceDTO } from "../../generated/models/PriceDTO"; -const priceControllerApi = new PriceListControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const priceControllerApi = new PriceListControllerApi(customConfiguration()); export const getPrices = () => diff --git a/src/state/summary/actions.ts b/src/state/summary/actions.ts index 7292ca1a5..13250593f 100644 --- a/src/state/summary/actions.ts +++ b/src/state/summary/actions.ts @@ -1,16 +1,14 @@ import { Dispatch } from "redux"; -import { of, concat } from "rxjs"; -import { map, catchError, toArray } from "rxjs/operators"; +import { concat, of } from "rxjs"; +import { catchError, map, toArray } from "rxjs/operators"; import { AdmissionControllerApi, - Configuration, ExaminationControllerApi, LaboratoryControllerApi, OpdControllerApi, OperationControllerApi, - TherapyControllerApi, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { convertToSummaryData } from "../../libraries/reduxUtils/convert"; import { IAction } from "../types"; import { @@ -21,21 +19,19 @@ import { } from "./consts"; const operationControllerApi = new OperationControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); const admissionControllerApi = new AdmissionControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); -const opdControllerrApi = new OpdControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); +const opdControllerrApi = new OpdControllerApi(customConfiguration()); const examinationControllerApi = new ExaminationControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); const laboratoryControllerApi = new LaboratoryControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) + customConfiguration() ); export const loadSummaryData = diff --git a/src/state/therapies/actions.ts b/src/state/therapies/actions.ts index bfc72a61f..c6116ecc9 100644 --- a/src/state/therapies/actions.ts +++ b/src/state/therapies/actions.ts @@ -1,11 +1,10 @@ import { Dispatch } from "redux"; import { - Configuration, ReplaceTherapiesUsingPOSTRequest, TherapyControllerApi, TherapyRowDTO, } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { CREATE_THERAPY_FAIL, @@ -24,9 +23,7 @@ import { UPDATE_THERAPY_SUCCESS, } from "./consts"; -const therapyControllerApi = new TherapyControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const therapyControllerApi = new TherapyControllerApi(customConfiguration()); export const createTherapy = (thRowDTO: TherapyRowDTO) => diff --git a/src/state/visits/actions.ts b/src/state/visits/actions.ts index 3c947dff3..6ec3e1ced 100644 --- a/src/state/visits/actions.ts +++ b/src/state/visits/actions.ts @@ -1,26 +1,24 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; -import { Configuration, VisitsControllerApi, VisitDTO } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { VisitDTO, VisitsControllerApi } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { - CREATE_VISIT_RESET, + CREATE_VISIT_FAIL, CREATE_VISIT_LOADING, + CREATE_VISIT_RESET, CREATE_VISIT_SUCCESS, - CREATE_VISIT_FAIL, GET_VISIT_FAIL, GET_VISIT_LOADING, GET_VISIT_SUCCESS, GET_VISIT_SUCCESS_EMPTY, - UPDATE_VISIT_LOADING, - UPDATE_VISIT_SUCCESS, UPDATE_VISIT_FAIL, + UPDATE_VISIT_LOADING, UPDATE_VISIT_RESET, + UPDATE_VISIT_SUCCESS, } from "./consts"; -const visitsControllerApi = new VisitsControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const visitsControllerApi = new VisitsControllerApi(customConfiguration()); export const createVisit = (newVisit: VisitDTO) => diff --git a/src/state/ward/actions.ts b/src/state/ward/actions.ts index 5edecb3ca..800f1461f 100644 --- a/src/state/ward/actions.ts +++ b/src/state/ward/actions.ts @@ -1,13 +1,11 @@ import isEmpty from "lodash.isempty"; import { Dispatch } from "redux"; -import { Configuration, DiseaseDTO, WardControllerApi } from "../../generated"; -import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware"; +import { DiseaseDTO, WardControllerApi } from "../../generated"; +import { customConfiguration } from "../../libraries/apiUtils/configuration"; import { IAction } from "../types"; import { GET_WARD_FAIL, GET_WARD_LOADING, GET_WARD_SUCCESS } from "./consts"; -const wardControllerApi = new WardControllerApi( - new Configuration({ middleware: [applyTokenMiddleware] }) -); +const wardControllerApi = new WardControllerApi(customConfiguration()); export const getWards = () =>