cardus 0.0.4 → 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,68 +70,63 @@ 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, }) {
88
- try {
89
- const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
90
- const { integrationsService, addressesService } = this.services;
91
- // esto hay que pasarlo ya en los parametros
92
- const sellerAddress = warehouseId > 0
93
- ? yield addressesService.getWarehouseAddress(idUsuario)
94
- : yield addressesService.getAddress(addressId, idUsuario);
95
- const allShopifyOrders = yield fetchAllOrders();
96
- const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
97
- idUsuario,
98
- orders: allShopifyOrders,
99
- type: this.type,
100
- });
101
- const insertOrdersResult = yield new this.executionManager({
102
- arrayParams: allShopifyOrders,
103
- executable: (order) => __awaiter(this, void 0, void 0, function* () {
104
- const parsedOrder = modificarOrdenOriginal({ originalOrder: order });
105
- const duplicatedTempShipment = yield integrationsService.checkDuplicateTempShipment(parsedOrder.codigoEnvioExterno, idUsuario);
106
- if (duplicatedTempShipment)
107
- return;
108
- return this.insertOrder({
109
- order: parsedOrder,
110
- agencyId,
111
- warehouseId,
112
- sellerAddress,
113
- idUsuario,
114
- group,
115
- });
116
- }),
117
- regularExecutionTime: 100, // ms
118
- initialBatchQuantity: 1, // de uno en uno
119
- }).upload();
120
- const successfullShipments = insertOrdersResult
121
- .filter(Boolean)
122
- .filter((each) => each.status === "fulfilled")
123
- .map((each) => each.value);
124
- yield this.insertQuantityRelatedLines({
125
- orders: successfullShipments,
126
- idUsuario,
127
- crearBulto,
128
- estaAgrupado,
129
- });
130
- return filteredOrders;
131
- }
132
- catch (e) {
133
- console.log(e);
134
- }
87
+ return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
88
+ const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
89
+ const { integrationsService, addressesService } = this.services;
90
+ // esto hay que pasarlo ya en los parametros
91
+ const sellerAddress = warehouseId > 0
92
+ ? yield addressesService.getWarehouseAddress(idUsuario)
93
+ : yield addressesService.getAddress(addressId, idUsuario);
94
+ const allShopifyOrders = yield fetchAllOrders();
95
+ const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
96
+ idUsuario,
97
+ orders: allShopifyOrders,
98
+ type: this.type
99
+ });
100
+ const insertOrdersResult = yield new this.executionManager({
101
+ arrayParams: allShopifyOrders,
102
+ executable: (order) => __awaiter(this, void 0, void 0, function* () {
103
+ const parsedOrder = modificarOrdenOriginal({ originalOrder: order });
104
+ const duplicatedTempShipment = yield integrationsService.checkDuplicateTempShipment(parsedOrder.codigoEnvioExterno, idUsuario);
105
+ if (duplicatedTempShipment)
106
+ return;
107
+ return this.insertOrder({
108
+ order: parsedOrder,
109
+ agencyId,
110
+ warehouseId,
111
+ sellerAddress,
112
+ idUsuario,
113
+ group
114
+ });
115
+ }),
116
+ regularExecutionTime: 100, // ms
117
+ initialBatchQuantity: 1 // de uno en uno
118
+ }).upload();
119
+ const successfullShipments = insertOrdersResult
120
+ .filter(Boolean)
121
+ .filter((each) => each.status === 'fulfilled')
122
+ .map((each) => each.value);
123
+ yield this.insertQuantityRelatedLines({
124
+ orders: successfullShipments,
125
+ idUsuario,
126
+ crearBulto,
127
+ estaAgrupado
128
+ });
129
+ return filteredOrders;
135
130
  });
136
131
  }
137
132
  insertQuantityRelatedLines(_a) {
@@ -144,26 +139,34 @@ class IntegrationManager {
144
139
  return yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
145
140
  const { bulto, cantidad = 0 } = yield crearBulto({
146
141
  lineItems: { idEnvioTemporal, line },
147
- idUsuario,
142
+ idUsuario
148
143
  });
149
144
  if (cantidad === 0)
150
145
  return null;
151
146
  return { bulto, cantidad, idEnvioTemporal };
152
147
  })));
153
148
  }));
154
- 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* () {
155
150
  const bultosYCantidadesAnidados = yield Promise.all(obtenerBultosYCantidades);
156
- const bultosYCantidades = bultosYCantidadesAnidados.flat().filter(Boolean);
151
+ const bultosYCantidades = bultosYCantidadesAnidados
152
+ .flat()
153
+ .filter(Boolean);
157
154
  res(bultosYCantidades);
158
- }));
155
+ })));
159
156
  bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
160
157
  try {
161
158
  const arrayFake = Array.from({ length: Number(cantidad) });
162
159
  arrayFake.forEach(() => {
163
160
  if (!estaAgrupado) {
164
- quantityRelatedFunctions.push(integrationsService.insertTempShipmentLines({ id_envio: idEnvioTemporal, bulto }));
161
+ quantityRelatedFunctions.push(integrationsService.insertTempShipmentLines({
162
+ id_envio: idEnvioTemporal,
163
+ bulto
164
+ }));
165
165
  }
166
- quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({ id_envio: idEnvioTemporal, bulto }));
166
+ quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({
167
+ id_envio: idEnvioTemporal,
168
+ bulto
169
+ }));
167
170
  });
168
171
  }
169
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
- direccion: order.direccionLLegada2
62
- ? order.direccionLLegada1 + " " + order.direccionLLegada2
63
+ direccion_llegada: 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;