cardus 0.0.5 → 0.0.6

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/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ dist
2
+ node_modules
package/.eslintrc ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "parser": "@typescript-eslint/parser",
3
+ "parserOptions": {
4
+ "ecmaVersion": 12,
5
+ "sourceType": "module"
6
+ },
7
+ "plugins": ["@typescript-eslint"],
8
+ "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
9
+ "rules": {},
10
+ "env": {
11
+ "browser": false,
12
+ "es2021": true
13
+ }
14
+ }
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+
2
+
3
+ {
4
+ "semi": true,
5
+ "trailingComma": "none",
6
+ "singleQuote": true,
7
+ "printWidth": 80
8
+ }
package/dist/index.js CHANGED
@@ -23,14 +23,14 @@ class IntegrationManager {
23
23
  agencyId,
24
24
  warehouseId,
25
25
  sellerAddress,
26
- idUsuario,
26
+ idUsuario
27
27
  });
28
28
  if (!idEnvioTemporal)
29
29
  throw new Error('Temp shipments could not be created');
30
30
  yield this.insertExternalShipment({
31
31
  idUsuario,
32
32
  order,
33
- idEnvioTemporal,
33
+ idEnvioTemporal
34
34
  });
35
35
  const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
36
36
  if (grouped)
@@ -46,7 +46,7 @@ class IntegrationManager {
46
46
  sellerAddress,
47
47
  idUsuario,
48
48
  findNextPickupDate: this.findNextPickupDate,
49
- countriesService: this.services.countriesService,
49
+ countriesService: this.services.countriesService
50
50
  });
51
51
  return yield this.services.integrationsService.insertTempShipment(tempShipmentData);
52
52
  });
@@ -55,9 +55,9 @@ class IntegrationManager {
55
55
  id_envio_temporal_usuario: idEnvioTemporal,
56
56
  codigo_envio_externo: order.codigoEnvioExterno,
57
57
  id_usuario: idUsuario,
58
- fecha_hora_creacion: (0, moment_1.default)().format("YYYY-MM-DD HH:mm:ss"),
58
+ fecha_hora_creacion: (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss'),
59
59
  servicio: this.type,
60
- id_interno_shopify: order.idInternoShopify,
60
+ id_interno_shopify: order.idInternoShopify
61
61
  });
62
62
  return idEnvioExterno;
63
63
  });
@@ -70,21 +70,21 @@ class IntegrationManager {
70
70
  peso: group.weight,
71
71
  alto: group.height,
72
72
  ancho: group.width,
73
- largo: group.length,
74
- },
73
+ largo: group.length
74
+ }
75
75
  });
76
76
  });
77
77
  this.services = {
78
78
  integrationsService: params.integrationsService,
79
79
  addressesService: params.addressesService,
80
- countriesService: params.countriesService,
80
+ countriesService: params.countriesService
81
81
  };
82
82
  this.type = params.type;
83
83
  this.executionManager = params.executionManager;
84
84
  this.findNextPickupDate = params.findNextPickupDate;
85
85
  }
86
86
  insertTempShipments(_a) {
87
- return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal, }) {
87
+ return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
88
88
  const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
89
89
  const { integrationsService, addressesService } = this.services;
90
90
  // esto hay que pasarlo ya en los parametros
@@ -95,7 +95,7 @@ class IntegrationManager {
95
95
  const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
96
96
  idUsuario,
97
97
  orders: allShopifyOrders,
98
- type: this.type,
98
+ type: this.type
99
99
  });
100
100
  const insertOrdersResult = yield new this.executionManager({
101
101
  arrayParams: allShopifyOrders,
@@ -110,21 +110,21 @@ class IntegrationManager {
110
110
  warehouseId,
111
111
  sellerAddress,
112
112
  idUsuario,
113
- group,
113
+ group
114
114
  });
115
115
  }),
116
116
  regularExecutionTime: 100, // ms
117
- initialBatchQuantity: 1, // de uno en uno
117
+ initialBatchQuantity: 1 // de uno en uno
118
118
  }).upload();
119
119
  const successfullShipments = insertOrdersResult
120
120
  .filter(Boolean)
121
- .filter((each) => each.status === "fulfilled")
121
+ .filter((each) => each.status === 'fulfilled')
122
122
  .map((each) => each.value);
123
123
  yield this.insertQuantityRelatedLines({
124
124
  orders: successfullShipments,
125
125
  idUsuario,
126
126
  crearBulto,
127
- estaAgrupado,
127
+ estaAgrupado
128
128
  });
129
129
  return filteredOrders;
130
130
  });
@@ -139,26 +139,34 @@ class IntegrationManager {
139
139
  return yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
140
140
  const { bulto, cantidad = 0 } = yield crearBulto({
141
141
  lineItems: { idEnvioTemporal, line },
142
- idUsuario,
142
+ idUsuario
143
143
  });
144
144
  if (cantidad === 0)
145
145
  return null;
146
146
  return { bulto, cantidad, idEnvioTemporal };
147
147
  })));
148
148
  }));
149
- const bultosYCantidades = yield new Promise((res) => __awaiter(this, void 0, void 0, function* () {
149
+ const bultosYCantidades = (yield new Promise((res) => __awaiter(this, void 0, void 0, function* () {
150
150
  const bultosYCantidadesAnidados = yield Promise.all(obtenerBultosYCantidades);
151
- const bultosYCantidades = bultosYCantidadesAnidados.flat().filter(Boolean);
151
+ const bultosYCantidades = bultosYCantidadesAnidados
152
+ .flat()
153
+ .filter(Boolean);
152
154
  res(bultosYCantidades);
153
- }));
155
+ })));
154
156
  bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
155
157
  try {
156
158
  const arrayFake = Array.from({ length: Number(cantidad) });
157
159
  arrayFake.forEach(() => {
158
160
  if (!estaAgrupado) {
159
- quantityRelatedFunctions.push(integrationsService.insertTempShipmentLines({ id_envio: idEnvioTemporal, bulto }));
161
+ quantityRelatedFunctions.push(integrationsService.insertTempShipmentLines({
162
+ id_envio: idEnvioTemporal,
163
+ bulto
164
+ }));
160
165
  }
161
- quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({ id_envio: idEnvioTemporal, bulto }));
166
+ quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({
167
+ id_envio: idEnvioTemporal,
168
+ bulto
169
+ }));
162
170
  });
163
171
  }
164
172
  catch (e) {
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.cookTempShipment = void 0;
16
16
  const moment_1 = __importDefault(require("moment"));
17
- const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ order, type, agencyId, warehouseId, sellerAddress, idUsuario, findNextPickupDate, countriesService, }) {
17
+ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ order, type, agencyId, warehouseId, sellerAddress, idUsuario, findNextPickupDate, countriesService }) {
18
18
  let zonaLLegada = {};
19
19
  if (order.codigoPaisLLegada)
20
20
  zonaLLegada = yield countriesService.getCountryFromCountryCode(order.codigoPaisLLegada);
@@ -31,21 +31,23 @@ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ or
31
31
  tlf_salida: sellerAddress.telefono,
32
32
  observaciones_salida: sellerAddress.observaciones,
33
33
  contacto_salida: sellerAddress.nombre,
34
- mail_salida: sellerAddress.mail,
34
+ mail_salida: sellerAddress.mail
35
35
  });
36
36
  const setUbicacionComprador = (order) => __awaiter(void 0, void 0, void 0, function* () {
37
37
  const compradorLocation = {
38
38
  pais_llegada: null,
39
39
  provincia_llegada: null,
40
- id_zona_llegada: null,
40
+ id_zona_llegada: null
41
41
  };
42
42
  if (order.codigoPaisLLegada) {
43
43
  const _zonaLLegada = zonaLLegada;
44
44
  compradorLocation.pais_llegada = (_zonaLLegada === null || _zonaLLegada === void 0 ? void 0 : _zonaLLegada.nombre_pais) || null;
45
45
  if ((_zonaLLegada === null || _zonaLLegada === void 0 ? void 0 : _zonaLLegada.id_pais) && order.codigoPostalLLegada) {
46
46
  const oTempShipmentProvincia = yield countriesService.getProvinceByCountryIdAndPostalCode(_zonaLLegada.id_pais, order.codigoPostalLLegada);
47
- compradorLocation.provincia_llegada = (oTempShipmentProvincia === null || oTempShipmentProvincia === void 0 ? void 0 : oTempShipmentProvincia.nombre_provincia) || null;
48
- compradorLocation.id_zona_llegada = yield countriesService.getZoneIdByCountryIdAndPostalCode(_zonaLLegada.id_pais, order.codigoPostalLLegada);
47
+ compradorLocation.provincia_llegada =
48
+ (oTempShipmentProvincia === null || oTempShipmentProvincia === void 0 ? void 0 : oTempShipmentProvincia.nombre_provincia) || null;
49
+ compradorLocation.id_zona_llegada =
50
+ yield countriesService.getZoneIdByCountryIdAndPostalCode(_zonaLLegada.id_pais, order.codigoPostalLLegada);
49
51
  }
50
52
  }
51
53
  return compradorLocation;
@@ -53,27 +55,27 @@ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ or
53
55
  const setDatosComprador = (order) => __awaiter(void 0, void 0, void 0, function* () {
54
56
  return ({
55
57
  nom_ape_llegada: order.primerApellidoLLegada
56
- ? order.nombreLLegada + " " + order.primerApellidoLLegada
58
+ ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
57
59
  : order.nombreLLegada,
58
60
  contacto_llegada: order.primerApellidoLLegada
59
- ? order.nombreLLegada + " " + order.primerApellidoLLegada
61
+ ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
60
62
  : order.nombreLLegada,
61
63
  direccion_llegada: order.direccionLLegada2
62
- ? order.direccionLLegada1 + " " + order.direccionLLegada2
64
+ ? order.direccionLLegada1 + ' ' + order.direccionLLegada2
63
65
  : order.direccionLLegada1,
64
66
  cod_pos_llegada: order.codigoPostalLLegada,
65
67
  poblacion_llegada: order.ciudadLLegada,
66
- tlf_llegada: order.telefonoLLegada || "no informado",
67
- mail_llegada: order.emailLLegada || "no informado",
68
+ tlf_llegada: order.telefonoLLegada || 'no informado',
69
+ mail_llegada: order.emailLLegada || 'no informado'
68
70
  });
69
71
  });
70
72
  const setReembolso = (order) => {
71
73
  return { cantidad_contrareembolso: order.cantidadContrareembolso };
72
74
  };
73
75
  const setFechas = (order) => __awaiter(void 0, void 0, void 0, function* () {
74
- const date = (0, moment_1.default)().format("YYYY-MM-DD");
75
- const beginHour = "09:00";
76
- const afterHour = "13:00";
76
+ const date = (0, moment_1.default)().format('YYYY-MM-DD');
77
+ const beginHour = '09:00';
78
+ const afterHour = '13:00';
77
79
  if (order.codigoPaisLLegada) {
78
80
  const _zonaLLegada = zonaLLegada;
79
81
  const oDeliveryDate = yield findNextPickupDate({
@@ -83,32 +85,39 @@ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ or
83
85
  idAgencia: agencyId
84
86
  });
85
87
  if (oDeliveryDate) {
86
- const deliveryDateFramgents = oDeliveryDate.fecha_recogida_horas.split(",");
88
+ const deliveryDateFramgents = oDeliveryDate.fecha_recogida_horas.split(',');
87
89
  return {
88
90
  fecha_recogida: deliveryDateFramgents[0],
89
91
  hora_desde: deliveryDateFramgents[1],
90
- hora_hasta: deliveryDateFramgents[2],
92
+ hora_hasta: deliveryDateFramgents[2]
91
93
  };
92
94
  }
93
95
  }
94
96
  return {
95
97
  fecha_recogida: date,
96
98
  hora_desde: beginHour,
97
- hora_hasta: afterHour,
99
+ hora_hasta: afterHour
98
100
  };
99
101
  });
100
102
  const setBultos = (order) => ({
101
103
  num_bultos: warehouseId ? 0 : order.lineas.length,
102
104
  tipo_envio: type,
103
105
  codigo_envio_externo: order.codigoEnvioExterno,
104
- id_almacen: warehouseId,
106
+ id_almacen: warehouseId
105
107
  });
106
- const setters = [setDatosVendedor, setDatosComprador, setUbicacionComprador, setReembolso, setFechas, setBultos];
107
- const dataInsert = yield setters.reduce((acc, curr) => __awaiter(void 0, void 0, void 0, function* () {
108
+ const setters = [
109
+ setDatosVendedor,
110
+ setDatosComprador,
111
+ setUbicacionComprador,
112
+ setReembolso,
113
+ setFechas,
114
+ setBultos
115
+ ];
116
+ const dataInsert = (yield setters.reduce((acc, curr) => __awaiter(void 0, void 0, void 0, function* () {
108
117
  const accumulated = yield acc;
109
118
  const stepResult = yield curr(Object.assign(Object.assign({}, order), accumulated));
110
119
  return Object.assign(Object.assign({}, accumulated), stepResult);
111
- }), {});
120
+ }), {}));
112
121
  return dataInsert;
113
122
  });
114
123
  exports.cookTempShipment = cookTempShipment;