sysone-api-mapper 1.0.134 → 1.0.135

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sysone-api-mapper",
3
- "version": "1.0.134",
3
+ "version": "1.0.135",
4
4
  "description": "Paquete mapper para portal de productores",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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 ? dayjs(e.dateFrom, 'DD/MM/YYYY').toISOString() : null,
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 ? dayjs(e.dateFrom, 'DD/MM/YYYY').toISOString() : null,
64
- validityTo: e.dateTo ? dayjs(e.dateTo, 'DD/MM/YYYY').toISOString() : null,
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: p.issueDate ? dayjs(p.issueDate, 'DD/MM/YYYY').toISOString() : null,
113
+ validityFrom: parseSafeDate(p.issueDate),
89
114
  validityTo: "N/A",
90
- ingress: p.issueDate ? dayjs(p.issueDate, 'DD/MM/YYYY').toISOString() : null,
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 ? dayjs(response.vigencyDateFrom, 'YYYY/MM/DD').toISOString() : null,
318
- dateTo: response?.vigencyDateTo ? dayjs(response.vigencyDateTo, 'YYYY/MM/DD').toISOString() : null,
342
+ dateFrom: response?.vigencyDateFrom ? parseSafeDate(response.vigencyDateFrom) : null,
343
+ dateTo: response?.vigencyDateTo ? parseSafeDate(response.vigencyDateTo) : null,
319
344
  },
320
- creationDate: response?.issueDate ? dayjs(response.issueDate, 'YYYY/MM/DD').toISOString() : null,
345
+ creationDate: response?.issueDate ? parseSafeDate(response.issueDate) : null,
321
346
  renewable: true,
322
347
  process: {
323
348
  name: response?.status?.name || null,