sysone-api-mapper 1.0.91 → 1.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/mapper/Mapper.js +12 -2
package/package.json
CHANGED
package/src/mapper/Mapper.js
CHANGED
|
@@ -90,6 +90,15 @@ const configs = {
|
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
const getUrl = (serviceUrl, routeParams) => {
|
|
94
|
+
if (!routeParams || routeParams.length === 0) return serviceUrl;
|
|
95
|
+
return serviceUrl.replace(/{(\d+)}/g, function (match, routeParamNumber) {
|
|
96
|
+
return routeParams[routeParamNumber]
|
|
97
|
+
? routeParams[routeParamNumber]
|
|
98
|
+
: match;
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
93
102
|
|
|
94
103
|
export const apiMapper = async (
|
|
95
104
|
endpointCode,
|
|
@@ -138,8 +147,8 @@ export const apiMapper = async (
|
|
|
138
147
|
validateStatus: (status) => status < 500,
|
|
139
148
|
};
|
|
140
149
|
|
|
141
|
-
const
|
|
142
|
-
|
|
150
|
+
const urlWithParams = getUrl(endpointData.url, routeParams);
|
|
151
|
+
const fullUrl = `${config.baseURL}${urlWithParams}`.replace(/([^:]\/)\/+/g, "$1");
|
|
143
152
|
|
|
144
153
|
let response;
|
|
145
154
|
let request;
|
|
@@ -150,6 +159,7 @@ export const apiMapper = async (
|
|
|
150
159
|
const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = request;
|
|
151
160
|
|
|
152
161
|
response = await axiosInstance.get(fullUrl, {
|
|
162
|
+
...config,
|
|
153
163
|
params: mappedParams,
|
|
154
164
|
responseType: responseType,
|
|
155
165
|
headers: {
|