cardus 0.0.107 → 0.0.108

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.
@@ -376,6 +376,46 @@ describe('IntegrationManager.insertTempShipments', () => {
376
376
  expect(addressesService.getAddress).not.toHaveBeenCalledWith(10, 77);
377
377
  });
378
378
 
379
+ it('uses sellerAddress from the order when addressId is not provided', async () => {
380
+ const { manager, addressesService, integrationsService } = buildFixture();
381
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
382
+
383
+ await manager.insertTempShipments({
384
+ payload: buildPayload({ addressId: null }),
385
+ fetchAllOrders: async () => [
386
+ buildOrder({
387
+ sellerAddress: {
388
+ id_pais: 44,
389
+ codigo_postal: '28001',
390
+ nombre: 'Origen Excel',
391
+ direccion: 'Calle Falsa 123',
392
+ poblacion: 'Madrid',
393
+ provincia: 'Madrid',
394
+ id_zona: 7,
395
+ nombre_pais: 'España',
396
+ telefono: '600000000',
397
+ observaciones: '',
398
+ mail: 'origen@example.com',
399
+ country_code_unico: 'ES'
400
+ }
401
+ })
402
+ ],
403
+ crearBulto: jest.fn(),
404
+ modificarOrdenOriginal: async ({ originalOrder }) => originalOrder
405
+ });
406
+
407
+ expect(addressesService.getAddress).not.toHaveBeenCalledWith(null, 77);
408
+ expect(integrationsService.insertTempShipment).toHaveBeenCalledWith(
409
+ expect.objectContaining({
410
+ nom_ape_salida: 'Origen Excel',
411
+ direccion_salida: 'Calle Falsa 123',
412
+ cod_pos_salida: '28001',
413
+ pais_salida: 'España'
414
+ }),
415
+ false
416
+ );
417
+ });
418
+
379
419
  it('passes shouldFindWarehouseSkus=true to insertQuantityRelatedLines when sku_almacen is enabled', async () => {
380
420
  const { manager } = buildFixture({ skuAlmacen: 1 });
381
421
  arrangeDefaultStubs({ manager, shipmentId: 12345 });
@@ -316,6 +316,42 @@ describe('IntegrationManager.insertTempShipments', () => {
316
316
  expect(addressesService.getWarehouseAddress).toHaveBeenCalledWith(77);
317
317
  expect(addressesService.getAddress).not.toHaveBeenCalledWith(10, 77);
318
318
  }));
319
+ it('uses sellerAddress from the order when addressId is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
320
+ const { manager, addressesService, integrationsService } = buildFixture();
321
+ arrangeDefaultStubs({ manager, shipmentId: 12345 });
322
+ yield manager.insertTempShipments({
323
+ payload: buildPayload({ addressId: null }),
324
+ fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () {
325
+ return [
326
+ buildOrder({
327
+ sellerAddress: {
328
+ id_pais: 44,
329
+ codigo_postal: '28001',
330
+ nombre: 'Origen Excel',
331
+ direccion: 'Calle Falsa 123',
332
+ poblacion: 'Madrid',
333
+ provincia: 'Madrid',
334
+ id_zona: 7,
335
+ nombre_pais: 'España',
336
+ telefono: '600000000',
337
+ observaciones: '',
338
+ mail: 'origen@example.com',
339
+ country_code_unico: 'ES'
340
+ }
341
+ })
342
+ ];
343
+ }),
344
+ crearBulto: jest.fn(),
345
+ modificarOrdenOriginal: (_c) => __awaiter(void 0, [_c], void 0, function* ({ originalOrder }) { return originalOrder; })
346
+ });
347
+ expect(addressesService.getAddress).not.toHaveBeenCalledWith(null, 77);
348
+ expect(integrationsService.insertTempShipment).toHaveBeenCalledWith(expect.objectContaining({
349
+ nom_ape_salida: 'Origen Excel',
350
+ direccion_salida: 'Calle Falsa 123',
351
+ cod_pos_salida: '28001',
352
+ pais_salida: 'España'
353
+ }), false);
354
+ }));
319
355
  it('passes shouldFindWarehouseSkus=true to insertQuantityRelatedLines when sku_almacen is enabled', () => __awaiter(void 0, void 0, void 0, function* () {
320
356
  const { manager } = buildFixture({ skuAlmacen: 1 });
321
357
  arrangeDefaultStubs({ manager, shipmentId: 12345 });
@@ -326,7 +362,7 @@ describe('IntegrationManager.insertTempShipments', () => {
326
362
  payload: buildPayload(),
327
363
  fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
328
364
  crearBulto: jest.fn(),
329
- modificarOrdenOriginal: (_c) => __awaiter(void 0, [_c], void 0, function* ({ originalOrder }) { return originalOrder; })
365
+ modificarOrdenOriginal: (_d) => __awaiter(void 0, [_d], void 0, function* ({ originalOrder }) { return originalOrder; })
330
366
  });
331
367
  insertQuantitySpy.mock.calls[0][0].shouldFindWarehouseSkus = true;
332
368
  expect(insertQuantitySpy).toHaveBeenCalledWith(expect.objectContaining({
@@ -353,7 +389,7 @@ describe('IntegrationManager.insertTempShipments', () => {
353
389
  }),
354
390
  fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
355
391
  crearBulto: jest.fn(),
356
- modificarOrdenOriginal: (_d) => __awaiter(void 0, [_d], void 0, function* ({ originalOrder }) { return originalOrder; })
392
+ modificarOrdenOriginal: (_e) => __awaiter(void 0, [_e], void 0, function* ({ originalOrder }) { return originalOrder; })
357
393
  });
358
394
  expect(insertQuantitySpy).toHaveBeenCalledWith(expect.objectContaining({
359
395
  group: {
@@ -367,7 +403,7 @@ describe('IntegrationManager.insertTempShipments', () => {
367
403
  expect(response.sequentialInsertion).toBe(false);
368
404
  }));
369
405
  it('updates agency when rule engine returns a different agency and uses shipment details in that decision', () => __awaiter(void 0, void 0, void 0, function* () {
370
- const getAgencyIdForTempShipment = jest.fn((_e) => __awaiter(void 0, [_e], void 0, function* ({ shipmentDetails }) {
406
+ const getAgencyIdForTempShipment = jest.fn((_f) => __awaiter(void 0, [_f], void 0, function* ({ shipmentDetails }) {
371
407
  expect(shipmentDetails).toEqual([
372
408
  expect.objectContaining({ id_envio: 12345, cantidad: 2 })
373
409
  ]);
@@ -381,7 +417,7 @@ describe('IntegrationManager.insertTempShipments', () => {
381
417
  payload: buildPayload({ agencyId: 50 }),
382
418
  fetchAllOrders: () => __awaiter(void 0, void 0, void 0, function* () { return [buildOrder()]; }),
383
419
  crearBulto: jest.fn(),
384
- modificarOrdenOriginal: (_f) => __awaiter(void 0, [_f], void 0, function* ({ originalOrder }) { return originalOrder; })
420
+ modificarOrdenOriginal: (_g) => __awaiter(void 0, [_g], void 0, function* ({ originalOrder }) { return originalOrder; })
385
421
  });
386
422
  expect(getAgencyIdForTempShipment).toHaveBeenCalledTimes(1);
387
423
  expect(integrationsService.updateTempShimpment).toHaveBeenCalledWith({
@@ -393,7 +429,7 @@ describe('IntegrationManager.insertTempShipments', () => {
393
429
  it('sends grouped package line to bulk insert when group=1 and order has more than one line', () => __awaiter(void 0, void 0, void 0, function* () {
394
430
  const { manager, integrationsService } = buildFixture();
395
431
  arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
396
- const crearBulto = jest.fn((_g) => __awaiter(void 0, [_g], void 0, function* ({ lineItems }) {
432
+ const crearBulto = jest.fn((_h) => __awaiter(void 0, [_h], void 0, function* ({ lineItems }) {
397
433
  return ({
398
434
  bulto: {
399
435
  peso: 1.2,
@@ -422,7 +458,7 @@ describe('IntegrationManager.insertTempShipments', () => {
422
458
  ];
423
459
  }),
424
460
  crearBulto,
425
- modificarOrdenOriginal: (_h) => __awaiter(void 0, [_h], void 0, function* ({ originalOrder }) { return originalOrder; })
461
+ modificarOrdenOriginal: (_j) => __awaiter(void 0, [_j], void 0, function* ({ originalOrder }) { return originalOrder; })
426
462
  });
427
463
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
428
464
  {
@@ -453,7 +489,7 @@ describe('IntegrationManager.insertTempShipments', () => {
453
489
  measuresFromConfig: 1
454
490
  });
455
491
  arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
456
- const crearBulto = jest.fn((_j) => __awaiter(void 0, [_j], void 0, function* ({ lineItems }) {
492
+ const crearBulto = jest.fn((_k) => __awaiter(void 0, [_k], void 0, function* ({ lineItems }) {
457
493
  return ({
458
494
  bulto: {
459
495
  peso: 1,
@@ -479,7 +515,7 @@ describe('IntegrationManager.insertTempShipments', () => {
479
515
  ];
480
516
  }),
481
517
  crearBulto,
482
- modificarOrdenOriginal: (_k) => __awaiter(void 0, [_k], void 0, function* ({ originalOrder }) { return originalOrder; })
518
+ modificarOrdenOriginal: (_l) => __awaiter(void 0, [_l], void 0, function* ({ originalOrder }) { return originalOrder; })
483
519
  });
484
520
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
485
521
  {
@@ -510,7 +546,7 @@ describe('IntegrationManager.insertTempShipments', () => {
510
546
  measuresFromConfig: 0
511
547
  });
512
548
  arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
513
- const crearBulto = jest.fn((_l) => __awaiter(void 0, [_l], void 0, function* ({ lineItems }) {
549
+ const crearBulto = jest.fn((_m) => __awaiter(void 0, [_m], void 0, function* ({ lineItems }) {
514
550
  return ({
515
551
  bulto: {
516
552
  peso: 2,
@@ -536,7 +572,7 @@ describe('IntegrationManager.insertTempShipments', () => {
536
572
  ];
537
573
  }),
538
574
  crearBulto,
539
- modificarOrdenOriginal: (_m) => __awaiter(void 0, [_m], void 0, function* ({ originalOrder }) { return originalOrder; })
575
+ modificarOrdenOriginal: (_o) => __awaiter(void 0, [_o], void 0, function* ({ originalOrder }) { return originalOrder; })
540
576
  });
541
577
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
542
578
  {
@@ -565,12 +601,12 @@ describe('IntegrationManager.insertTempShipments', () => {
565
601
  skuAlmacen: 1
566
602
  });
567
603
  arrangeRealQuantityFlow({ manager, shipmentId: 12345 });
568
- manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_o) => __awaiter(void 0, [_o], void 0, function* ({ sku }) {
604
+ manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_p) => __awaiter(void 0, [_p], void 0, function* ({ sku }) {
569
605
  return ({
570
606
  id: sku === 'SKU-01' ? 111 : 222
571
607
  });
572
608
  }));
573
- const crearBulto = jest.fn((_p) => __awaiter(void 0, [_p], void 0, function* ({ lineItems }) {
609
+ const crearBulto = jest.fn((_q) => __awaiter(void 0, [_q], void 0, function* ({ lineItems }) {
574
610
  return ({
575
611
  bulto: {
576
612
  peso: 2,
@@ -597,7 +633,7 @@ describe('IntegrationManager.insertTempShipments', () => {
597
633
  ];
598
634
  }),
599
635
  crearBulto,
600
- modificarOrdenOriginal: (_q) => __awaiter(void 0, [_q], void 0, function* ({ originalOrder }) { return originalOrder; })
636
+ modificarOrdenOriginal: (_r) => __awaiter(void 0, [_r], void 0, function* ({ originalOrder }) { return originalOrder; })
601
637
  });
602
638
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
603
639
  expect.objectContaining({ id_envio: 12345 }),
@@ -626,7 +662,7 @@ describe('IntegrationManager.insertTempShipments', () => {
626
662
  manager,
627
663
  shipmentIds: [2001, 2002]
628
664
  });
629
- const crearBulto = jest.fn((_r) => __awaiter(void 0, [_r], void 0, function* ({ lineItems }) {
665
+ const crearBulto = jest.fn((_s) => __awaiter(void 0, [_s], void 0, function* ({ lineItems }) {
630
666
  return ({
631
667
  bulto: {
632
668
  peso: 1.5,
@@ -664,7 +700,7 @@ describe('IntegrationManager.insertTempShipments', () => {
664
700
  ];
665
701
  }),
666
702
  crearBulto,
667
- modificarOrdenOriginal: (_s) => __awaiter(void 0, [_s], void 0, function* ({ originalOrder }) { return originalOrder; })
703
+ modificarOrdenOriginal: (_t) => __awaiter(void 0, [_t], void 0, function* ({ originalOrder }) { return originalOrder; })
668
704
  });
669
705
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
670
706
  {
@@ -700,7 +736,7 @@ describe('IntegrationManager.insertTempShipments', () => {
700
736
  manager,
701
737
  shipmentIds: [2101, 2102]
702
738
  });
703
- const crearBulto = jest.fn((_t) => __awaiter(void 0, [_t], void 0, function* ({ lineItems }) {
739
+ const crearBulto = jest.fn((_u) => __awaiter(void 0, [_u], void 0, function* ({ lineItems }) {
704
740
  return ({
705
741
  bulto: {
706
742
  peso: 2,
@@ -737,7 +773,7 @@ describe('IntegrationManager.insertTempShipments', () => {
737
773
  ];
738
774
  }),
739
775
  crearBulto,
740
- modificarOrdenOriginal: (_u) => __awaiter(void 0, [_u], void 0, function* ({ originalOrder }) { return originalOrder; })
776
+ modificarOrdenOriginal: (_v) => __awaiter(void 0, [_v], void 0, function* ({ originalOrder }) { return originalOrder; })
741
777
  });
742
778
  const linesArg = integrationsService.insertTempShipmentMultipleLines.mock.calls[0][0];
743
779
  expect(linesArg).toHaveLength(8);
@@ -767,7 +803,7 @@ describe('IntegrationManager.insertTempShipments', () => {
767
803
  manager,
768
804
  shipmentIds: [2201, 2202]
769
805
  });
770
- const crearBulto = jest.fn((_v) => __awaiter(void 0, [_v], void 0, function* ({ lineItems }) {
806
+ const crearBulto = jest.fn((_w) => __awaiter(void 0, [_w], void 0, function* ({ lineItems }) {
771
807
  return ({
772
808
  bulto: {
773
809
  peso: 1,
@@ -798,7 +834,7 @@ describe('IntegrationManager.insertTempShipments', () => {
798
834
  ];
799
835
  }),
800
836
  crearBulto,
801
- modificarOrdenOriginal: (_w) => __awaiter(void 0, [_w], void 0, function* ({ originalOrder }) { return originalOrder; })
837
+ modificarOrdenOriginal: (_x) => __awaiter(void 0, [_x], void 0, function* ({ originalOrder }) { return originalOrder; })
802
838
  });
803
839
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
804
840
  {
@@ -832,7 +868,7 @@ describe('IntegrationManager.insertTempShipments', () => {
832
868
  manager,
833
869
  shipmentIds: [2301, 2302]
834
870
  });
835
- const crearBulto = jest.fn((_x) => __awaiter(void 0, [_x], void 0, function* ({ lineItems }) {
871
+ const crearBulto = jest.fn((_y) => __awaiter(void 0, [_y], void 0, function* ({ lineItems }) {
836
872
  return ({
837
873
  bulto: {
838
874
  peso: 3,
@@ -863,7 +899,7 @@ describe('IntegrationManager.insertTempShipments', () => {
863
899
  ];
864
900
  }),
865
901
  crearBulto,
866
- modificarOrdenOriginal: (_y) => __awaiter(void 0, [_y], void 0, function* ({ originalOrder }) { return originalOrder; })
902
+ modificarOrdenOriginal: (_z) => __awaiter(void 0, [_z], void 0, function* ({ originalOrder }) { return originalOrder; })
867
903
  });
868
904
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
869
905
  {
@@ -911,14 +947,14 @@ describe('IntegrationManager.insertTempShipments', () => {
911
947
  manager,
912
948
  shipmentIds: [2401, 2402]
913
949
  });
914
- manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_z) => __awaiter(void 0, [_z], void 0, function* ({ sku }) {
950
+ manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_0) => __awaiter(void 0, [_0], void 0, function* ({ sku }) {
915
951
  if (sku === 'SKU-I1')
916
952
  return { id: 901 };
917
953
  if (sku === 'SKU-J1')
918
954
  return { id: 902 };
919
955
  return { id: 999 };
920
956
  }));
921
- const crearBulto = jest.fn((_0) => __awaiter(void 0, [_0], void 0, function* ({ lineItems }) {
957
+ const crearBulto = jest.fn((_1) => __awaiter(void 0, [_1], void 0, function* ({ lineItems }) {
922
958
  return ({
923
959
  bulto: {
924
960
  peso: 2,
@@ -956,7 +992,7 @@ describe('IntegrationManager.insertTempShipments', () => {
956
992
  ];
957
993
  }),
958
994
  crearBulto,
959
- modificarOrdenOriginal: (_1) => __awaiter(void 0, [_1], void 0, function* ({ originalOrder }) { return originalOrder; })
995
+ modificarOrdenOriginal: (_2) => __awaiter(void 0, [_2], void 0, function* ({ originalOrder }) { return originalOrder; })
960
996
  });
961
997
  expect(integrationsService.insertTempShipmentMultipleJsonQuantityReferences).toHaveBeenCalledWith([
962
998
  {
@@ -1003,7 +1039,7 @@ describe('IntegrationManager.insertTempShipments', () => {
1003
1039
  manager,
1004
1040
  shipmentIds: [2501, 2502]
1005
1041
  });
1006
- const crearBulto = jest.fn((_2) => __awaiter(void 0, [_2], void 0, function* ({ lineItems }) {
1042
+ const crearBulto = jest.fn((_3) => __awaiter(void 0, [_3], void 0, function* ({ lineItems }) {
1007
1043
  const groupedOrderLine = lineItems.line.sku_producto.startsWith('SKU-K');
1008
1044
  return {
1009
1045
  bulto: {
@@ -1038,7 +1074,7 @@ describe('IntegrationManager.insertTempShipments', () => {
1038
1074
  ];
1039
1075
  }),
1040
1076
  crearBulto,
1041
- modificarOrdenOriginal: (_3) => __awaiter(void 0, [_3], void 0, function* ({ originalOrder }) { return originalOrder; })
1077
+ modificarOrdenOriginal: (_4) => __awaiter(void 0, [_4], void 0, function* ({ originalOrder }) { return originalOrder; })
1042
1078
  });
1043
1079
  expect(integrationsService.insertTempShipmentMultipleLines).toHaveBeenCalledWith([
1044
1080
  {
@@ -1079,8 +1115,8 @@ describe('IntegrationManager.insertTempShipments', () => {
1079
1115
  manager.services.integrationsService.insertTempShipment
1080
1116
  .mockResolvedValueOnce(2601)
1081
1117
  .mockResolvedValueOnce(2602);
1082
- manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_4) => __awaiter(void 0, [_4], void 0, function* ({ sku }) { return ({ id: sku === 'SKU-M1' ? 7001 : 7002 }); }));
1083
- manager.getModifiedOrderBasedOnRules = jest.fn((_5) => __awaiter(void 0, [_5], void 0, function* ({ parsedOrder }) {
1118
+ manager.services.warehouseService.getProductReferenceFromSku = jest.fn((_5) => __awaiter(void 0, [_5], void 0, function* ({ sku }) { return ({ id: sku === 'SKU-M1' ? 7001 : 7002 }); }));
1119
+ manager.getModifiedOrderBasedOnRules = jest.fn((_6) => __awaiter(void 0, [_6], void 0, function* ({ parsedOrder }) {
1084
1120
  if (parsedOrder.codigoEnvioExterno === 'EXT-ABORT') {
1085
1121
  return {
1086
1122
  partialTempShipmentModified: { abort_creation: true },
@@ -1092,7 +1128,7 @@ describe('IntegrationManager.insertTempShipments', () => {
1092
1128
  packagesModified: []
1093
1129
  };
1094
1130
  }));
1095
- const crearBulto = jest.fn((_6) => __awaiter(void 0, [_6], void 0, function* ({ lineItems }) {
1131
+ const crearBulto = jest.fn((_7) => __awaiter(void 0, [_7], void 0, function* ({ lineItems }) {
1096
1132
  return ({
1097
1133
  bulto: {
1098
1134
  peso: 2,
@@ -1124,7 +1160,7 @@ describe('IntegrationManager.insertTempShipments', () => {
1124
1160
  ];
1125
1161
  }),
1126
1162
  crearBulto,
1127
- modificarOrdenOriginal: (_7) => __awaiter(void 0, [_7], void 0, function* ({ originalOrder }) { return originalOrder; })
1163
+ modificarOrdenOriginal: (_8) => __awaiter(void 0, [_8], void 0, function* ({ originalOrder }) { return originalOrder; })
1128
1164
  });
1129
1165
  const linesArg = integrationsService.insertTempShipmentMultipleLines.mock.calls[0][0];
1130
1166
  const detailsArg = integrationsService.insertTempShipmentMultipleDetails.mock.calls[0][0];
package/dist/index.js CHANGED
@@ -61,11 +61,12 @@ class IntegrationManager {
61
61
  return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group, sequentialInsertion = false }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
62
62
  const user = yield this.services.usersService.obtenerUsuarioId(idUsuario);
63
63
  const { integrationsService, addressesService } = this.services;
64
- // esto hay que pasarlo ya en los parametros
65
- const sellerAddress = warehouseId > 0
64
+ const defaultSellerAddress = warehouseId > 0
66
65
  ? yield addressesService.getWarehouseAddress(idUsuario)
67
- : yield addressesService.getAddress(addressId, idUsuario);
68
- const country = yield this.services.countriesService.getCountry(sellerAddress.id_pais);
66
+ : addressId
67
+ ? yield addressesService.getAddress(addressId, idUsuario)
68
+ : null;
69
+ let sellerAddressForContents = defaultSellerAddress;
69
70
  const userIntegrationConfiguration = yield integrationsService.getDefaultIntegrationsData({
70
71
  id_usuario: idUsuario,
71
72
  id_integracion: this.integrationType
@@ -94,6 +95,7 @@ class IntegrationManager {
94
95
  const insertOrdersResult = yield new this.executionManager({
95
96
  arrayParams: filteredOrders,
96
97
  executable: (order) => __awaiter(this, void 0, void 0, function* () {
98
+ var _b;
97
99
  const parsedOrder = yield modificarOrdenOriginal({
98
100
  originalOrder: order
99
101
  });
@@ -101,12 +103,17 @@ class IntegrationManager {
101
103
  if (parsedOrder.direccionSalidaId) {
102
104
  direccionSalida = yield addressesService.getAddress(parsedOrder.direccionSalidaId, idUsuario);
103
105
  }
106
+ const currentSellerAddress = (_b = direccionSalida !== null && direccionSalida !== void 0 ? direccionSalida : parsedOrder.sellerAddress) !== null && _b !== void 0 ? _b : defaultSellerAddress;
107
+ if (!currentSellerAddress) {
108
+ throw new Error('Seller address could not be resolved');
109
+ }
110
+ sellerAddressForContents !== null && sellerAddressForContents !== void 0 ? sellerAddressForContents : (sellerAddressForContents = currentSellerAddress);
104
111
  const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
105
112
  order: parsedOrder,
106
113
  shipmentType: this.shipmentType,
107
114
  agencyId,
108
115
  warehouseId,
109
- sellerAddress: direccionSalida !== null && direccionSalida !== void 0 ? direccionSalida : sellerAddress,
116
+ sellerAddress: currentSellerAddress,
110
117
  idUsuario,
111
118
  findNextPickupDate: this.findNextPickupDate,
112
119
  countriesService: this.services.countriesService,
@@ -127,7 +134,7 @@ class IntegrationManager {
127
134
  userId: idUsuario,
128
135
  integrationId: this.integrationType,
129
136
  parsedOrder,
130
- sellerAddress,
137
+ sellerAddress: currentSellerAddress,
131
138
  shipmentDetails,
132
139
  tempShipmentData,
133
140
  packages: this.dataToInsert.lines.get(idEnvioTemporal) || []
@@ -164,7 +171,7 @@ class IntegrationManager {
164
171
  acc[tempShipmentId].push(curr);
165
172
  return acc;
166
173
  }, {});
167
- yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_b) => __awaiter(this, [_b], void 0, function* ([tempShipmentId, bultosYCantidades]) {
174
+ yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
168
175
  const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
169
176
  idUsuario,
170
177
  warehouseId,
@@ -191,6 +198,10 @@ class IntegrationManager {
191
198
  regularExecutionTime: 8000, // ms
192
199
  initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
193
200
  }).upload();
201
+ if (!sellerAddressForContents) {
202
+ throw new Error('Seller address could not be resolved');
203
+ }
204
+ const country = yield this.services.countriesService.getCountry(sellerAddressForContents.id_pais);
194
205
  // content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
195
206
  yield this.insertUserDefaultConfigurationContent({
196
207
  user,
package/index.ts CHANGED
@@ -111,15 +111,13 @@ export class IntegrationManager {
111
111
  }: InsertParams) {
112
112
  const user = await this.services.usersService.obtenerUsuarioId(idUsuario);
113
113
  const { integrationsService, addressesService } = this.services;
114
- // esto hay que pasarlo ya en los parametros
115
- const sellerAddress =
114
+ const defaultSellerAddress =
116
115
  warehouseId > 0
117
116
  ? await addressesService.getWarehouseAddress(idUsuario)
118
- : await addressesService.getAddress(addressId, idUsuario);
119
-
120
- const country = await this.services.countriesService.getCountry(
121
- sellerAddress.id_pais
122
- );
117
+ : addressId
118
+ ? await addressesService.getAddress(addressId, idUsuario)
119
+ : null;
120
+ let sellerAddressForContents = defaultSellerAddress;
123
121
 
124
122
  const userIntegrationConfiguration =
125
123
  await integrationsService.getDefaultIntegrationsData({
@@ -176,13 +174,21 @@ export class IntegrationManager {
176
174
  idUsuario
177
175
  );
178
176
  }
177
+ const currentSellerAddress =
178
+ direccionSalida ?? parsedOrder.sellerAddress ?? defaultSellerAddress;
179
+
180
+ if (!currentSellerAddress) {
181
+ throw new Error('Seller address could not be resolved');
182
+ }
183
+
184
+ sellerAddressForContents ??= currentSellerAddress;
179
185
 
180
186
  const tempShipmentData = await cookTempShipment({
181
187
  order: parsedOrder,
182
188
  shipmentType: this.shipmentType,
183
189
  agencyId,
184
190
  warehouseId,
185
- sellerAddress: direccionSalida ?? sellerAddress,
191
+ sellerAddress: currentSellerAddress,
186
192
  idUsuario,
187
193
  findNextPickupDate: this.findNextPickupDate,
188
194
  countriesService: this.services.countriesService,
@@ -213,7 +219,7 @@ export class IntegrationManager {
213
219
  userId: idUsuario,
214
220
  integrationId: this.integrationType,
215
221
  parsedOrder,
216
- sellerAddress,
222
+ sellerAddress: currentSellerAddress,
217
223
  shipmentDetails,
218
224
  tempShipmentData,
219
225
  packages: this.dataToInsert.lines.get(idEnvioTemporal) || []
@@ -307,6 +313,14 @@ export class IntegrationManager {
307
313
  initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
308
314
  }).upload();
309
315
 
316
+ if (!sellerAddressForContents) {
317
+ throw new Error('Seller address could not be resolved');
318
+ }
319
+
320
+ const country = await this.services.countriesService.getCountry(
321
+ sellerAddressForContents.id_pais
322
+ );
323
+
310
324
  // content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
311
325
  await this.insertUserDefaultConfigurationContent({
312
326
  user,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.107",
3
+ "version": "0.0.108",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -123,7 +123,7 @@ export type ModifiedOrder = {
123
123
  telefonoLLegada: string | undefined;
124
124
  emailLLegada: string | undefined;
125
125
  cantidadContrareembolso: number | null;
126
- codigoEnvioExterno?: string;
126
+ codigoEnvioExterno: string;
127
127
  idInternoShopify?: string;
128
128
  precio: number | null;
129
129
  fechaCreacionExterna?: string | null;
@@ -139,6 +139,7 @@ export type ModifiedOrder = {
139
139
  observacionesLLegada?: string;
140
140
  observaciones?: string;
141
141
  direccionSalidaId?: number | null;
142
+ sellerAddress?: SellerAddress | null;
142
143
  };
143
144
 
144
145
  export interface ModifiedOrderExtended extends ModifiedOrder {
@@ -468,7 +469,7 @@ export type InsertContentShipmentDetail = {
468
469
 
469
470
  type InsertContentShipmentExternal = {
470
471
  id_envio_temporal_usuario: number;
471
- codigo_envio_externo: string | undefined;
472
+ codigo_envio_externo: string;
472
473
  id_usuario: number;
473
474
  fecha_hora_creacion: string;
474
475
  servicio: Type;