cardus 0.0.107 → 0.0.111

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,16 @@ 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.direccionSalidaPersonalizada) !== null && _b !== void 0 ? _b : defaultSellerAddress;
107
+ if (!currentSellerAddress) {
108
+ throw new Error('Seller address could not be resolved');
109
+ }
104
110
  const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
105
111
  order: parsedOrder,
106
112
  shipmentType: this.shipmentType,
107
113
  agencyId,
108
114
  warehouseId,
109
- sellerAddress: direccionSalida !== null && direccionSalida !== void 0 ? direccionSalida : sellerAddress,
115
+ sellerAddress: currentSellerAddress,
110
116
  idUsuario,
111
117
  findNextPickupDate: this.findNextPickupDate,
112
118
  countriesService: this.services.countriesService,
@@ -127,7 +133,7 @@ class IntegrationManager {
127
133
  userId: idUsuario,
128
134
  integrationId: this.integrationType,
129
135
  parsedOrder,
130
- sellerAddress,
136
+ sellerAddress: currentSellerAddress,
131
137
  shipmentDetails,
132
138
  tempShipmentData,
133
139
  packages: this.dataToInsert.lines.get(idEnvioTemporal) || []
@@ -164,7 +170,7 @@ class IntegrationManager {
164
170
  acc[tempShipmentId].push(curr);
165
171
  return acc;
166
172
  }, {});
167
- yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_b) => __awaiter(this, [_b], void 0, function* ([tempShipmentId, bultosYCantidades]) {
173
+ yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
168
174
  const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
169
175
  idUsuario,
170
176
  warehouseId,
@@ -186,16 +192,21 @@ class IntegrationManager {
186
192
  });
187
193
  // details
188
194
  this.dataToInsert.details.push(...shipmentDetails);
195
+ const country = yield this.services.countriesService.getCountry(currentSellerAddress.id_pais);
196
+ // mete los contents
197
+ yield this.insertUserDefaultConfigurationContent({
198
+ user,
199
+ countryName: country.nombre_pais_en,
200
+ shipmentDetails
201
+ });
189
202
  return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
190
203
  }),
191
204
  regularExecutionTime: 8000, // ms
192
205
  initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
193
206
  }).upload();
194
- // content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
195
- yield this.insertUserDefaultConfigurationContent({
196
- user,
197
- countryName: country.nombre_pais_en
198
- });
207
+ if (!sellerAddressForContents) {
208
+ throw new Error('Seller address could not be resolved');
209
+ }
199
210
  const arrayPackages = [...this.dataToInsert.lines.values()].flat().flat();
200
211
  yield Promise.allSettled([
201
212
  integrationsService.insertTempShipmentMultipleLines(arrayPackages),
@@ -216,7 +227,7 @@ class IntegrationManager {
216
227
  });
217
228
  }
218
229
  insertUserDefaultConfigurationContent(_a) {
219
- return __awaiter(this, arguments, void 0, function* ({ user, countryName }) {
230
+ return __awaiter(this, arguments, void 0, function* ({ user, countryName, shipmentDetails }) {
220
231
  const idUsuario = user.id_usuario;
221
232
  const { configurationService, llmAPIService } = this.services;
222
233
  const insert = (data) => {
@@ -234,10 +245,8 @@ class IntegrationManager {
234
245
  const getRandomContentValue = () => {
235
246
  return Math.floor(Math.random() * 5) + 1;
236
247
  };
237
- const integrationShipmentDetails = this.dataToInsert.details;
248
+ const integrationShipmentDetails = shipmentDetails;
238
249
  let shipmentContent = null;
239
- const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
240
- [];
241
250
  if (integrationShipmentDetails) {
242
251
  const shipmentContentFromDetails = yield Promise.all(integrationShipmentDetails.map((detail) => __awaiter(this, void 0, void 0, function* () {
243
252
  let taric = null;
@@ -270,12 +279,15 @@ class IntegrationManager {
270
279
  })));
271
280
  shipmentContent = shipmentContentFromDetails;
272
281
  }
273
- else if (userSavedData.length > 0) {
274
- shipmentContent = userSavedData;
275
- }
276
282
  else {
277
- const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
278
- shipmentContent = userFakeData;
283
+ const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
284
+ if (userSavedData.length > 0) {
285
+ shipmentContent = userSavedData;
286
+ }
287
+ else {
288
+ const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
289
+ shipmentContent = userFakeData;
290
+ }
279
291
  }
280
292
  if (shipmentContent) {
281
293
  shipmentContent = cleanContentData(shipmentContent);
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 ??
179
+ parsedOrder.direccionSalidaPersonalizada ??
180
+ defaultSellerAddress;
181
+
182
+ if (!currentSellerAddress) {
183
+ throw new Error('Seller address could not be resolved');
184
+ }
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) || []
@@ -301,17 +307,26 @@ export class IntegrationManager {
301
307
  // details
302
308
  this.dataToInsert.details.push(...shipmentDetails);
303
309
 
310
+ const country = await this.services.countriesService.getCountry(
311
+ currentSellerAddress.id_pais
312
+ );
313
+
314
+ // mete los contents
315
+ await this.insertUserDefaultConfigurationContent({
316
+ user,
317
+ countryName: country.nombre_pais_en,
318
+ shipmentDetails
319
+ });
320
+
304
321
  return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
305
322
  },
306
323
  regularExecutionTime: 8000, // ms
307
324
  initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
308
325
  }).upload();
309
326
 
310
- // content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
311
- await this.insertUserDefaultConfigurationContent({
312
- user,
313
- countryName: country.nombre_pais_en
314
- });
327
+ if (!sellerAddressForContents) {
328
+ throw new Error('Seller address could not be resolved');
329
+ }
315
330
 
316
331
  const arrayPackages = [...this.dataToInsert.lines.values()].flat().flat();
317
332
 
@@ -348,10 +363,12 @@ export class IntegrationManager {
348
363
 
349
364
  async insertUserDefaultConfigurationContent({
350
365
  user,
351
- countryName
366
+ countryName,
367
+ shipmentDetails
352
368
  }: {
353
369
  user: Record<string, string | number>;
354
370
  countryName: string;
371
+ shipmentDetails: InsertContentShipmentDetail[];
355
372
  }) {
356
373
  const idUsuario = user.id_usuario as number;
357
374
  const { configurationService, llmAPIService } = this.services;
@@ -382,11 +399,8 @@ export class IntegrationManager {
382
399
  return Math.floor(Math.random() * 5) + 1;
383
400
  };
384
401
 
385
- const integrationShipmentDetails = this.dataToInsert.details;
402
+ const integrationShipmentDetails = shipmentDetails;
386
403
  let shipmentContent: UserDefaultConfigurationContent[] | null = null;
387
- const userSavedData =
388
- (await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
389
- [];
390
404
 
391
405
  if (integrationShipmentDetails) {
392
406
  const shipmentContentFromDetails = await Promise.all(
@@ -424,15 +438,22 @@ export class IntegrationManager {
424
438
  );
425
439
 
426
440
  shipmentContent = shipmentContentFromDetails;
427
- } else if (userSavedData.length > 0) {
428
- shipmentContent = userSavedData;
429
441
  } else {
430
- const userFakeData =
431
- configurationService.getFakeDefaultProformaConfiguration(
432
- idUsuario,
433
- user.dni as string
434
- );
435
- shipmentContent = userFakeData;
442
+ const userSavedData =
443
+ (await configurationService.getDefaultProformaConfiguration(
444
+ idUsuario
445
+ )) || [];
446
+
447
+ if (userSavedData.length > 0) {
448
+ shipmentContent = userSavedData;
449
+ } else {
450
+ const userFakeData =
451
+ configurationService.getFakeDefaultProformaConfiguration(
452
+ idUsuario,
453
+ user.dni as string
454
+ );
455
+ shipmentContent = userFakeData;
456
+ }
436
457
  }
437
458
 
438
459
  if (shipmentContent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.107",
3
+ "version": "0.0.111",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -139,6 +139,7 @@ export type ModifiedOrder = {
139
139
  observacionesLLegada?: string;
140
140
  observaciones?: string;
141
141
  direccionSalidaId?: number | null;
142
+ direccionSalidaPersonalizada?: SellerAddress | null;
142
143
  };
143
144
 
144
145
  export interface ModifiedOrderExtended extends ModifiedOrder {