cardus 0.0.15 → 0.0.17

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/index.ts CHANGED
@@ -40,7 +40,7 @@ export class IntegrationManager {
40
40
  addressesService: AddressesService;
41
41
  countriesService: CountriesService;
42
42
  configurationService: ConfigurationService;
43
- userService: UsersService;
43
+ usersService: UsersService;
44
44
  type: Type;
45
45
  shipmentType: ShipmentType;
46
46
  executionManager: ExecutionManager;
@@ -51,7 +51,7 @@ export class IntegrationManager {
51
51
  addressesService: params.addressesService,
52
52
  countriesService: params.countriesService,
53
53
  configurationService: params.configurationService,
54
- usersService: params.userService
54
+ usersService: params.usersService
55
55
  };
56
56
  this.shipmentType = params.shipmentType;
57
57
  this.type = params.type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/dist/index.js DELETED
@@ -1,215 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.IntegrationManager = void 0;
16
- const moment_1 = __importDefault(require("moment"));
17
- const insertTempShipment_1 = require("./insertTempShipment");
18
- class IntegrationManager {
19
- constructor(params) {
20
- this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, group }) {
21
- const idEnvioTemporal = yield this.insertTempShipment({
22
- order,
23
- agencyId,
24
- warehouseId,
25
- sellerAddress,
26
- idUsuario
27
- });
28
- if (!idEnvioTemporal)
29
- throw new Error('Temp shipments could not be created');
30
- yield this.insertExternalShipment({
31
- idUsuario,
32
- order,
33
- idEnvioTemporal
34
- });
35
- const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
36
- if (grouped)
37
- yield this.insertTempShipmentLines({ idEnvioTemporal, group });
38
- return Object.assign(order, { idEnvioTemporal });
39
- });
40
- this.insertTempShipment = (_b) => __awaiter(this, [_b], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario }) {
41
- const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
42
- order,
43
- shipmentType: this.shipmentType,
44
- agencyId,
45
- warehouseId,
46
- sellerAddress,
47
- idUsuario,
48
- findNextPickupDate: this.findNextPickupDate,
49
- countriesService: this.services.countriesService
50
- });
51
- return yield this.services.integrationsService.insertTempShipment(tempShipmentData);
52
- });
53
- this.insertExternalShipment = (_c) => __awaiter(this, [_c], void 0, function* ({ idUsuario, order, idEnvioTemporal }) {
54
- const idEnvioExterno = yield this.services.integrationsService.insertExternalShipment({
55
- id_envio_temporal_usuario: idEnvioTemporal,
56
- codigo_envio_externo: order.codigoEnvioExterno,
57
- id_usuario: idUsuario,
58
- fecha_hora_creacion: (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss'),
59
- servicio: this.type,
60
- id_interno_shopify: order.idInternoShopify
61
- });
62
- return idEnvioExterno;
63
- });
64
- this.insertTempShipmentLines = (_d) => __awaiter(this, [_d], void 0, function* ({ idEnvioTemporal, group }) {
65
- const grouped = group.grouped === 1 || group.grouped === '1';
66
- if (grouped)
67
- yield this.services.integrationsService.insertTempShipmentLines({
68
- id_envio: idEnvioTemporal,
69
- bulto: {
70
- peso: group.weight,
71
- alto: group.height,
72
- ancho: group.width,
73
- largo: group.length
74
- }
75
- });
76
- });
77
- this.services = {
78
- integrationsService: params.integrationsService,
79
- addressesService: params.addressesService,
80
- countriesService: params.countriesService,
81
- configurationService: params.configurationService,
82
- usersService: params.userService
83
- };
84
- this.shipmentType = params.shipmentType;
85
- this.type = params.type;
86
- this.executionManager = params.executionManager;
87
- this.findNextPickupDate = params.findNextPickupDate;
88
- }
89
- insertTempShipments(_a) {
90
- return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
91
- const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
92
- const { integrationsService, addressesService } = this.services;
93
- // esto hay que pasarlo ya en los parametros
94
- const sellerAddress = warehouseId > 0
95
- ? yield addressesService.getWarehouseAddress(idUsuario)
96
- : yield addressesService.getAddress(addressId, idUsuario);
97
- const allOrders = yield fetchAllOrders();
98
- const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
99
- idUsuario,
100
- orders: allOrders,
101
- type: this.type
102
- });
103
- const insertOrdersResult = yield new this.executionManager({
104
- arrayParams: allOrders,
105
- executable: (order) => __awaiter(this, void 0, void 0, function* () {
106
- const parsedOrder = yield modificarOrdenOriginal({
107
- originalOrder: order
108
- });
109
- const duplicatedTempShipment = yield integrationsService.checkDuplicateTempShipment(parsedOrder.codigoEnvioExterno, idUsuario);
110
- if (duplicatedTempShipment)
111
- throw new Error('Envio Duplicado');
112
- return this.insertOrder({
113
- order: parsedOrder,
114
- agencyId,
115
- warehouseId,
116
- sellerAddress,
117
- idUsuario,
118
- group
119
- });
120
- }),
121
- regularExecutionTime: 100, // ms
122
- initialBatchQuantity: 5 // de cinco en cinco
123
- }).upload();
124
- const successfullShipments = insertOrdersResult
125
- .filter(Boolean)
126
- .filter((each) => each.status === 'fulfilled')
127
- .map((each) => each.value);
128
- yield this.insertQuantityRelatedLines({
129
- orders: successfullShipments,
130
- idUsuario,
131
- crearBulto,
132
- estaAgrupado
133
- });
134
- yield this.insertUserDefaultConfigurationContent({
135
- idUsuario,
136
- tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
137
- });
138
- return filteredOrders;
139
- });
140
- }
141
- insertUserDefaultConfigurationContent(_a) {
142
- return __awaiter(this, arguments, void 0, function* ({ idUsuario, tempShimpmentIds }) {
143
- const { usersService, configurationService, integrationsService } = this.services;
144
- const insert = (data, tempShimpmentId) => __awaiter(this, void 0, void 0, function* () {
145
- return Promise.allSettled(data.map((tempContent) => __awaiter(this, void 0, void 0, function* () {
146
- yield integrationsService.insertTempContent(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
147
- })));
148
- });
149
- const insertOrdersResult = yield new this.executionManager({
150
- arrayParams: tempShimpmentIds,
151
- executable: (order) => __awaiter(this, void 0, void 0, function* () {
152
- const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
153
- if (userSavedData.length > 0) {
154
- yield insert(userSavedData, order);
155
- }
156
- else {
157
- const user = yield usersService.obtenerUsuarioId(idUsuario);
158
- const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
159
- yield insert(userFakeData, order);
160
- }
161
- }),
162
- regularExecutionTime: 100, // ms
163
- initialBatchQuantity: 5 // de cinco en cinco
164
- }).upload();
165
- });
166
- }
167
- insertQuantityRelatedLines(_a) {
168
- return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
169
- const { integrationsService } = this.services;
170
- const quantityRelatedFunctions = [];
171
- const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
172
- if (!idEnvioTemporal)
173
- return null;
174
- return yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
175
- const { bulto, cantidad = 0 } = yield crearBulto({
176
- lineItems: { idEnvioTemporal, line },
177
- idUsuario
178
- });
179
- if (cantidad === 0)
180
- return null;
181
- return { bulto, cantidad, idEnvioTemporal };
182
- })));
183
- }));
184
- const bultosYCantidades = (yield new Promise((res) => __awaiter(this, void 0, void 0, function* () {
185
- const bultosYCantidadesAnidados = yield Promise.all(obtenerBultosYCantidades);
186
- const bultosYCantidades = bultosYCantidadesAnidados
187
- .flat()
188
- .filter(Boolean);
189
- res(bultosYCantidades);
190
- })));
191
- bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
192
- try {
193
- const arrayFake = Array.from({ length: Number(cantidad) });
194
- arrayFake.forEach(() => {
195
- if (!estaAgrupado) {
196
- quantityRelatedFunctions.push(integrationsService.insertTempShipmentLines({
197
- id_envio: idEnvioTemporal,
198
- bulto
199
- }));
200
- }
201
- quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({
202
- id_envio: idEnvioTemporal,
203
- bulto
204
- }));
205
- });
206
- }
207
- catch (e) {
208
- console.log(e);
209
- }
210
- });
211
- yield Promise.allSettled(quantityRelatedFunctions);
212
- });
213
- }
214
- }
215
- exports.IntegrationManager = IntegrationManager;
@@ -1,123 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.cookTempShipment = void 0;
16
- const moment_1 = __importDefault(require("moment"));
17
- const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ order, shipmentType, agencyId, warehouseId, sellerAddress, idUsuario, findNextPickupDate, countriesService }) {
18
- let zonaLLegada = {};
19
- if (order.codigoPaisLLegada)
20
- zonaLLegada = yield countriesService.getCountryFromCountryCode(order.codigoPaisLLegada);
21
- const setDatosVendedor = () => ({
22
- id_usuario: idUsuario,
23
- id_agencia: agencyId,
24
- nom_ape_salida: sellerAddress.nombre,
25
- direccion_salida: sellerAddress.direccion,
26
- cod_pos_salida: sellerAddress.codigo_postal,
27
- poblacion_salida: sellerAddress.poblacion,
28
- provincia_salida: sellerAddress.provincia,
29
- id_zona_salida: sellerAddress.id_zona,
30
- pais_salida: sellerAddress.nombre_pais,
31
- tlf_salida: sellerAddress.telefono,
32
- observaciones_salida: sellerAddress.observaciones,
33
- contacto_salida: sellerAddress.nombre,
34
- mail_salida: sellerAddress.mail
35
- });
36
- const setUbicacionComprador = (order) => __awaiter(void 0, void 0, void 0, function* () {
37
- const compradorLocation = {
38
- pais_llegada: null,
39
- provincia_llegada: null,
40
- id_zona_llegada: null
41
- };
42
- if (order.codigoPaisLLegada) {
43
- const _zonaLLegada = zonaLLegada;
44
- compradorLocation.pais_llegada = (_zonaLLegada === null || _zonaLLegada === void 0 ? void 0 : _zonaLLegada.nombre_pais) || null;
45
- if ((_zonaLLegada === null || _zonaLLegada === void 0 ? void 0 : _zonaLLegada.id_pais) && order.codigoPostalLLegada) {
46
- const oTempShipmentProvincia = yield countriesService.getProvinceByCountryIdAndPostalCode(_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);
51
- }
52
- }
53
- return compradorLocation;
54
- });
55
- const setDatosComprador = (order) => __awaiter(void 0, void 0, void 0, function* () {
56
- return ({
57
- nom_ape_llegada: order.primerApellidoLLegada
58
- ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
59
- : order.nombreLLegada,
60
- contacto_llegada: order.primerApellidoLLegada
61
- ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
62
- : order.nombreLLegada,
63
- direccion_llegada: order.direccionLLegada2
64
- ? order.direccionLLegada1 + ' ' + order.direccionLLegada2
65
- : order.direccionLLegada1,
66
- cod_pos_llegada: order.codigoPostalLLegada,
67
- poblacion_llegada: order.ciudadLLegada,
68
- tlf_llegada: order.telefonoLLegada || 'no informado',
69
- mail_llegada: order.emailLLegada || 'no informado'
70
- });
71
- });
72
- const setReembolso = (order) => {
73
- return { cantidad_contrareembolso: order.cantidadContrareembolso };
74
- };
75
- const setFechas = (order) => __awaiter(void 0, void 0, void 0, function* () {
76
- const date = (0, moment_1.default)().format('YYYY-MM-DD');
77
- const beginHour = '09:00';
78
- const afterHour = '13:00';
79
- if (order.codigoPaisLLegada) {
80
- const _zonaLLegada = zonaLLegada;
81
- const oDeliveryDate = yield findNextPickupDate({
82
- cp_salida: sellerAddress.codigo_postal,
83
- id_pais_origen: sellerAddress.id_pais,
84
- id_pais_destino: _zonaLLegada.id_pais,
85
- idAgencia: agencyId
86
- });
87
- if (oDeliveryDate) {
88
- const deliveryDateFramgents = oDeliveryDate.fecha_recogida_horas.split(',');
89
- return {
90
- fecha_recogida: deliveryDateFramgents[0],
91
- hora_desde: deliveryDateFramgents[1],
92
- hora_hasta: deliveryDateFramgents[2]
93
- };
94
- }
95
- }
96
- return {
97
- fecha_recogida: date,
98
- hora_desde: beginHour,
99
- hora_hasta: afterHour
100
- };
101
- });
102
- const setBultos = (order) => ({
103
- num_bultos: warehouseId ? 0 : order.lineas.length,
104
- tipo_envio: shipmentType,
105
- codigo_envio_externo: order.codigoEnvioExterno,
106
- id_almacen: warehouseId
107
- });
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* () {
117
- const accumulated = yield acc;
118
- const stepResult = yield curr(Object.assign(Object.assign({}, order), accumulated));
119
- return Object.assign(Object.assign({}, accumulated), stepResult);
120
- }), {}));
121
- return dataInsert;
122
- });
123
- exports.cookTempShipment = cookTempShipment;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const shipmentTypes = {
4
- NORMAL: 1,
5
- EXCEL: 7,
6
- RECTIFICATIVO: 8,
7
- PRESTASHOP_MODULE: 15,
8
- API: 16,
9
- EBAY: 17,
10
- ABONO: 18,
11
- WOOCOMMERCE: 19,
12
- ALIEXPRESS: 22,
13
- SHOPIFY: 23,
14
- ECWID: 31,
15
- CARGOS: 40,
16
- DAILY_PICKUP: 50,
17
- FLASH_SHIPMENT: 51,
18
- WITHDRAWALL: 52,
19
- SHIPMENT_SCHEME: 53,
20
- PRESTASHOP: 115,
21
- AMAZON: 118,
22
- JOOM: 119,
23
- HOLDED: 120,
24
- ETSY: 121,
25
- NORMAL_V2: 122
26
- };