sysone-api-mapper 1.0.134 → 1.0.136
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
CHANGED
package/src/mapper/Mapper.js
CHANGED
|
@@ -99,6 +99,13 @@ const getUrl = (serviceUrl, routeParams) => {
|
|
|
99
99
|
});
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
const normalizeTenant = (tenant) => {
|
|
103
|
+
if (!tenant || typeof tenant !== "string") return tenant;
|
|
104
|
+
|
|
105
|
+
// Toma solo lo que está antes del primer "/"
|
|
106
|
+
return tenant.split("/")[0];
|
|
107
|
+
};
|
|
108
|
+
|
|
102
109
|
|
|
103
110
|
export const apiMapper = async (
|
|
104
111
|
endpointCode,
|
|
@@ -109,10 +116,11 @@ export const apiMapper = async (
|
|
|
109
116
|
) => {
|
|
110
117
|
try {
|
|
111
118
|
const configData = tenantsConfig[endpointCode];
|
|
119
|
+
const normalizedTenant = normalizeTenant(tenant);
|
|
112
120
|
if (!configData)
|
|
113
121
|
throw new Error(`Endpoint no configurado: ${endpointCode}`);
|
|
114
122
|
|
|
115
|
-
const endpointData = configData[
|
|
123
|
+
const endpointData = configData[normalizedTenant] ?? configData.default;
|
|
116
124
|
|
|
117
125
|
if (endpointData === null) {
|
|
118
126
|
console.warn(`⚠️ No hay configuración para el endpoint ${endpointCode} y tenant ${tenant}, y no existe configuración por defecto.`);
|
|
@@ -125,9 +133,9 @@ export const apiMapper = async (
|
|
|
125
133
|
throw new Error("No se pudo cargar la configuración del API Mapper");
|
|
126
134
|
}
|
|
127
135
|
|
|
128
|
-
const dynamicHeaders = getDynamicHeaders(
|
|
136
|
+
const dynamicHeaders = getDynamicHeaders(normalizedTenant);
|
|
129
137
|
|
|
130
|
-
if (
|
|
138
|
+
if (normalizedTenant === "cnp") {
|
|
131
139
|
config = {
|
|
132
140
|
...configs.cnp,
|
|
133
141
|
headers: {
|
|
@@ -141,8 +149,8 @@ export const apiMapper = async (
|
|
|
141
149
|
...configs.default,
|
|
142
150
|
headers: {
|
|
143
151
|
...configs.default.headers,
|
|
144
|
-
["X-Tenant"]:
|
|
145
|
-
["X-User"]:
|
|
152
|
+
["X-Tenant"]: normalizedTenant,
|
|
153
|
+
["X-User"]: normalizedTenant,
|
|
146
154
|
...additionalHeaders
|
|
147
155
|
},
|
|
148
156
|
};
|
|
@@ -64,7 +64,7 @@ export const getProductsBySubsections_Request = (params) => {
|
|
|
64
64
|
|
|
65
65
|
export const partySearchParams = (params) => {
|
|
66
66
|
return {
|
|
67
|
-
firstName: params.firstName || null,
|
|
67
|
+
firstName: params.firstName || params.name || null,
|
|
68
68
|
lastName: params.lastName || null,
|
|
69
69
|
identification: params.identificationValue || null,
|
|
70
70
|
}
|
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
|
|
4
|
+
dayjs.extend(customParseFormat);
|
|
5
|
+
|
|
6
|
+
const parseSafeDate = (dateString) => {
|
|
7
|
+
if (!dateString) return null;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
// Parsear explícitamente con el formato DD/MM/YYYY
|
|
11
|
+
// El tercer parámetro 'true' activa el modo strict
|
|
12
|
+
const parsed = dayjs(dateString, 'DD/MM/YYYY', true);
|
|
13
|
+
|
|
14
|
+
// Verificar si la fecha es válida
|
|
15
|
+
if (!parsed.isValid()) {
|
|
16
|
+
console.warn(`Invalid date format: ${dateString}`);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return parsed.toISOString();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(`Error parsing date: ${dateString}`, error);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
2
27
|
|
|
3
28
|
const getInsureds_CNP = async (response) => {
|
|
4
29
|
const objectMapped = {
|
|
@@ -53,15 +78,15 @@ const getEndorsements_CNP = async (response) => {
|
|
|
53
78
|
const objectMapped = {
|
|
54
79
|
values:
|
|
55
80
|
response.endorsements.map((e) => ({
|
|
56
|
-
activeDate: e.dateFrom ?
|
|
81
|
+
activeDate: e.dateFrom ? parseSafeDate(e.dateFrom) : null,
|
|
57
82
|
number: e.number,
|
|
58
83
|
type: {
|
|
59
84
|
code: e.detail,
|
|
60
85
|
name: e.detail,
|
|
61
86
|
group: {}
|
|
62
87
|
},
|
|
63
|
-
validityFrom: e.dateFrom ?
|
|
64
|
-
validityTo: e.dateTo ?
|
|
88
|
+
validityFrom: e.dateFrom ? parseSafeDate(e.dateFrom) : null,
|
|
89
|
+
validityTo: e.dateTo ? parseSafeDate(e.dateTo) : null,
|
|
65
90
|
}))
|
|
66
91
|
,
|
|
67
92
|
total: response.endorsements.length,
|
|
@@ -85,9 +110,9 @@ const getPolicies_CNP = async (response) => {
|
|
|
85
110
|
const objectMapped = {
|
|
86
111
|
values: response.policies.map((p) => ({
|
|
87
112
|
number: p.number,
|
|
88
|
-
validityFrom:
|
|
113
|
+
validityFrom: parseSafeDate(p.issueDate),
|
|
89
114
|
validityTo: "N/A",
|
|
90
|
-
ingress:
|
|
115
|
+
ingress: parseSafeDate(p.issueDate),
|
|
91
116
|
holder: {
|
|
92
117
|
name: p.holder?.name || p.holder?.firstName,
|
|
93
118
|
identifications: {
|
|
@@ -314,10 +339,10 @@ const getPolicyCollectiveDetail_CNP = async (response) => {
|
|
|
314
339
|
code: response?.currency?.code || null,
|
|
315
340
|
months: "N/A"
|
|
316
341
|
},
|
|
317
|
-
dateFrom: response?.vigencyDateFrom ?
|
|
318
|
-
dateTo: response?.vigencyDateTo ?
|
|
342
|
+
dateFrom: response?.vigencyDateFrom ? parseSafeDate(response.vigencyDateFrom) : null,
|
|
343
|
+
dateTo: response?.vigencyDateTo ? parseSafeDate(response.vigencyDateTo) : null,
|
|
319
344
|
},
|
|
320
|
-
creationDate: response?.issueDate ?
|
|
345
|
+
creationDate: response?.issueDate ? parseSafeDate(response.issueDate) : null,
|
|
321
346
|
renewable: true,
|
|
322
347
|
process: {
|
|
323
348
|
name: response?.status?.name || null,
|