cardus 0.0.86 → 0.0.88

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/dist/index.js CHANGED
@@ -265,27 +265,35 @@ class IntegrationManager {
265
265
  });
266
266
  }
267
267
  createJsonQuantityReferencesFromLines(_a) {
268
- return __awaiter(this, arguments, void 0, function* ({ warehouseId, bultosYCantidades }) {
269
- if (warehouseId) {
270
- const json_referencias_cantidades = (yield Promise.all(bultosYCantidades.map((each) => __awaiter(this, void 0, void 0, function* () {
271
- const cantidad = each === null || each === void 0 ? void 0 : each.cantidad;
272
- const sku = each === null || each === void 0 ? void 0 : each.bulto.sku_producto;
273
- if (!cantidad || !sku)
274
- return [];
275
- const references = yield this.services.warehouseService.getProductReferenceFromSku(sku);
276
- const reference = references === null || references === void 0 ? void 0 : references[0];
277
- if (!(reference === null || reference === void 0 ? void 0 : reference.id))
278
- return [];
279
- return Array.from({ length: cantidad }, () => ({
280
- id_caja: -1,
281
- referencias: {
282
- [reference.id]: 1
268
+ return __awaiter(this, arguments, void 0, function* ({ idUsuario, warehouseId, bultosYCantidades }) {
269
+ try {
270
+ if (warehouseId) {
271
+ const json_referencias_cantidades = (yield Promise.all(bultosYCantidades.map((each) => __awaiter(this, void 0, void 0, function* () {
272
+ const cantidad = each === null || each === void 0 ? void 0 : each.cantidad;
273
+ const sku = each === null || each === void 0 ? void 0 : each.bulto.sku_producto;
274
+ if (!cantidad || !sku)
275
+ return [];
276
+ const reference = yield this.services.warehouseService.getProductReferenceFromSku({
277
+ idUsuario,
278
+ sku
279
+ });
280
+ if (!(reference === null || reference === void 0 ? void 0 : reference.id)) {
281
+ throw new Error('no existe sku para referencia');
283
282
  }
284
- }));
285
- })))).flat();
286
- return json_referencias_cantidades;
283
+ return Array.from({ length: cantidad }, () => ({
284
+ id_caja: -1,
285
+ referencias: {
286
+ [reference.id]: 1
287
+ }
288
+ }));
289
+ })))).flat();
290
+ return json_referencias_cantidades;
291
+ }
292
+ return [];
293
+ }
294
+ catch (e) {
295
+ return [];
287
296
  }
288
- return [];
289
297
  });
290
298
  }
291
299
  insertQuantityRelatedLines(_a) {
@@ -338,6 +346,7 @@ class IntegrationManager {
338
346
  }, {});
339
347
  yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
340
348
  const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
349
+ idUsuario,
341
350
  warehouseId,
342
351
  bultosYCantidades
343
352
  });
package/index.ts CHANGED
@@ -447,43 +447,53 @@ export class IntegrationManager {
447
447
  };
448
448
 
449
449
  async createJsonQuantityReferencesFromLines({
450
+ idUsuario,
450
451
  warehouseId,
451
452
  bultosYCantidades
452
453
  }: {
454
+ idUsuario: number;
453
455
  warehouseId: number;
454
456
  bultosYCantidades: BultoYCantidad[];
455
457
  }): Promise<JsonReferenciasCantidades | []> {
456
- if (warehouseId) {
457
- const json_referencias_cantidades = (
458
- await Promise.all(
459
- bultosYCantidades.map(async (each) => {
460
- const cantidad = each?.cantidad;
461
- const sku = each?.bulto.sku_producto;
462
-
463
- if (!cantidad || !sku) return [];
464
-
465
- const references =
466
- await this.services.warehouseService.getProductReferenceFromSku(
467
- sku
468
- );
469
- const reference = references?.[0];
470
-
471
- if (!reference?.id) return [];
472
-
473
- return Array.from({ length: cantidad }, () => ({
474
- id_caja: -1,
475
- referencias: {
476
- [reference.id]: 1
458
+ try {
459
+ if (warehouseId) {
460
+ const json_referencias_cantidades = (
461
+ await Promise.all(
462
+ bultosYCantidades.map(async (each) => {
463
+ const cantidad = each?.cantidad;
464
+ const sku = each?.bulto.sku_producto;
465
+
466
+ if (!cantidad || !sku) return [];
467
+
468
+ const reference =
469
+ await this.services.warehouseService.getProductReferenceFromSku(
470
+ {
471
+ idUsuario,
472
+ sku
473
+ }
474
+ );
475
+
476
+ if (!reference?.id) {
477
+ throw new Error('no existe sku para referencia');
477
478
  }
478
- }));
479
- })
480
- )
481
- ).flat();
482
479
 
483
- return json_referencias_cantidades;
484
- }
480
+ return Array.from({ length: cantidad }, () => ({
481
+ id_caja: -1,
482
+ referencias: {
483
+ [reference.id]: 1
484
+ }
485
+ }));
486
+ })
487
+ )
488
+ ).flat();
489
+
490
+ return json_referencias_cantidades;
491
+ }
485
492
 
486
- return [];
493
+ return [];
494
+ } catch (e) {
495
+ return [];
496
+ }
487
497
  }
488
498
 
489
499
  async insertQuantityRelatedLines({
@@ -567,6 +577,7 @@ export class IntegrationManager {
567
577
  async ([tempShipmentId, bultosYCantidades]) => {
568
578
  const json_referencias_cantidades =
569
579
  await this.createJsonQuantityReferencesFromLines({
580
+ idUsuario,
570
581
  warehouseId,
571
582
  bultosYCantidades
572
583
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -264,9 +264,10 @@ export type LlmAPIService = {
264
264
  };
265
265
 
266
266
  export type WarehouseService = {
267
- getProductReferenceFromSku: (
268
- sku: string
269
- ) => Promise<{ id: number; sku: string }[]>;
267
+ getProductReferenceFromSku: (params: {
268
+ idUsuario: number;
269
+ sku: string;
270
+ }) => Promise<{ id: number; sku: string }>;
270
271
  };
271
272
 
272
273
  export type JsonReferenciasCantidades = Array<{