cardus 0.0.87 → 0.0.89

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
@@ -149,12 +149,18 @@ class IntegrationManager {
149
149
  .filter(Boolean)
150
150
  .filter((each) => each.status === 'fulfilled')
151
151
  .map((each) => each.value);
152
+ const userIntegrationConfiguration = yield integrationsService.getDefaultIntegrationsData({
153
+ id_usuario: idUsuario,
154
+ id_integracion: this.integrationType
155
+ });
156
+ const shouldFindWarehouseSkus = !!userIntegrationConfiguration.buscar_sku_almacen;
152
157
  yield this.insertQuantityRelatedLines({
153
158
  orders: successfullShipments,
154
159
  idUsuario,
155
160
  crearBulto,
156
161
  group,
157
- warehouseId
162
+ warehouseId,
163
+ shouldFindWarehouseSkus
158
164
  });
159
165
  yield this.insertUserDefaultConfigurationContent({
160
166
  user,
@@ -265,7 +271,7 @@ class IntegrationManager {
265
271
  });
266
272
  }
267
273
  createJsonQuantityReferencesFromLines(_a) {
268
- return __awaiter(this, arguments, void 0, function* ({ warehouseId, bultosYCantidades }) {
274
+ return __awaiter(this, arguments, void 0, function* ({ idUsuario, warehouseId, bultosYCantidades }) {
269
275
  try {
270
276
  if (warehouseId) {
271
277
  const json_referencias_cantidades = (yield Promise.all(bultosYCantidades.map((each) => __awaiter(this, void 0, void 0, function* () {
@@ -273,8 +279,10 @@ class IntegrationManager {
273
279
  const sku = each === null || each === void 0 ? void 0 : each.bulto.sku_producto;
274
280
  if (!cantidad || !sku)
275
281
  return [];
276
- const references = yield this.services.warehouseService.getProductReferenceFromSku(sku);
277
- const reference = references === null || references === void 0 ? void 0 : references[0];
282
+ const reference = yield this.services.warehouseService.getProductReferenceFromSku({
283
+ idUsuario,
284
+ sku
285
+ });
278
286
  if (!(reference === null || reference === void 0 ? void 0 : reference.id)) {
279
287
  throw new Error('no existe sku para referencia');
280
288
  }
@@ -295,7 +303,7 @@ class IntegrationManager {
295
303
  });
296
304
  }
297
305
  insertQuantityRelatedLines(_a) {
298
- return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group, warehouseId }) {
306
+ return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group, warehouseId, shouldFindWarehouseSkus }) {
299
307
  /*
300
308
  basicamente la logica es:
301
309
  1 - si esta agrupado, crea una linea por cada pedido
@@ -333,27 +341,30 @@ class IntegrationManager {
333
341
  });
334
342
  let bultosYCantidades = yield Promise.all(obtenerBultosYCantidades);
335
343
  bultosYCantidades = bultosYCantidades.filter(Boolean);
336
- const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce((acc, curr) => {
337
- var _a;
338
- const tempShipmentId = curr === null || curr === void 0 ? void 0 : curr.idEnvioTemporal;
339
- if (!tempShipmentId)
344
+ if (shouldFindWarehouseSkus) {
345
+ const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce((acc, curr) => {
346
+ var _a;
347
+ const tempShipmentId = curr === null || curr === void 0 ? void 0 : curr.idEnvioTemporal;
348
+ if (!tempShipmentId)
349
+ return acc;
350
+ (_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
351
+ acc[tempShipmentId].push(curr);
340
352
  return acc;
341
- (_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
342
- acc[tempShipmentId].push(curr);
343
- return acc;
344
- }, {});
345
- yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
346
- const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
347
- warehouseId,
348
- bultosYCantidades
349
- });
350
- if (json_referencias_cantidades.length > 0) {
351
- this.dataToInsert.jsonQuantityReferences.push({
352
- id_envio: Number(tempShipmentId),
353
- json_referencias_cantidades
353
+ }, {});
354
+ yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
355
+ const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
356
+ idUsuario,
357
+ warehouseId,
358
+ bultosYCantidades
354
359
  });
355
- }
356
- })));
360
+ if (json_referencias_cantidades.length > 0) {
361
+ this.dataToInsert.jsonQuantityReferences.push({
362
+ id_envio: Number(tempShipmentId),
363
+ json_referencias_cantidades
364
+ });
365
+ }
366
+ })));
367
+ }
357
368
  bultosYCantidades.forEach((each) => {
358
369
  if (!each)
359
370
  return;
package/index.ts CHANGED
@@ -200,12 +200,21 @@ export class IntegrationManager {
200
200
  agencyId: number;
201
201
  })[];
202
202
 
203
+ const userIntegrationConfiguration =
204
+ await integrationsService.getDefaultIntegrationsData({
205
+ id_usuario: idUsuario,
206
+ id_integracion: this.integrationType
207
+ });
208
+ const shouldFindWarehouseSkus =
209
+ !!userIntegrationConfiguration.buscar_sku_almacen;
210
+
203
211
  await this.insertQuantityRelatedLines({
204
212
  orders: successfullShipments,
205
213
  idUsuario,
206
214
  crearBulto,
207
215
  group,
208
- warehouseId
216
+ warehouseId,
217
+ shouldFindWarehouseSkus
209
218
  });
210
219
 
211
220
  await this.insertUserDefaultConfigurationContent({
@@ -447,9 +456,11 @@ export class IntegrationManager {
447
456
  };
448
457
 
449
458
  async createJsonQuantityReferencesFromLines({
459
+ idUsuario,
450
460
  warehouseId,
451
461
  bultosYCantidades
452
462
  }: {
463
+ idUsuario: number;
453
464
  warehouseId: number;
454
465
  bultosYCantidades: BultoYCantidad[];
455
466
  }): Promise<JsonReferenciasCantidades | []> {
@@ -463,11 +474,13 @@ export class IntegrationManager {
463
474
 
464
475
  if (!cantidad || !sku) return [];
465
476
 
466
- const references =
477
+ const reference =
467
478
  await this.services.warehouseService.getProductReferenceFromSku(
468
- sku
479
+ {
480
+ idUsuario,
481
+ sku
482
+ }
469
483
  );
470
- const reference = references?.[0];
471
484
 
472
485
  if (!reference?.id) {
473
486
  throw new Error('no existe sku para referencia');
@@ -497,13 +510,15 @@ export class IntegrationManager {
497
510
  idUsuario,
498
511
  crearBulto,
499
512
  group,
500
- warehouseId
513
+ warehouseId,
514
+ shouldFindWarehouseSkus
501
515
  }: {
502
516
  orders: ModifiedOrderExtended[];
503
517
  idUsuario: number;
504
518
  crearBulto: CrearBulto;
505
519
  group: Group;
506
520
  warehouseId: number;
521
+ shouldFindWarehouseSkus: boolean;
507
522
  }) {
508
523
  /*
509
524
  basicamente la logica es:
@@ -556,36 +571,39 @@ export class IntegrationManager {
556
571
  let bultosYCantidades = await Promise.all(obtenerBultosYCantidades);
557
572
  bultosYCantidades = bultosYCantidades.filter(Boolean);
558
573
 
559
- const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce<
560
- Record<number, BultoYCantidad[]>
561
- >((acc, curr) => {
562
- const tempShipmentId = curr?.idEnvioTemporal;
563
- if (!tempShipmentId) return acc;
564
-
565
- acc[tempShipmentId] ??= [];
566
- acc[tempShipmentId].push(curr);
567
-
568
- return acc;
569
- }, {});
570
-
571
- await Promise.all(
572
- Object.entries(bultosYCantidadesGroupedByShipment).map(
573
- async ([tempShipmentId, bultosYCantidades]) => {
574
- const json_referencias_cantidades =
575
- await this.createJsonQuantityReferencesFromLines({
576
- warehouseId,
577
- bultosYCantidades
578
- });
579
-
580
- if (json_referencias_cantidades.length > 0) {
581
- this.dataToInsert.jsonQuantityReferences.push({
582
- id_envio: Number(tempShipmentId),
583
- json_referencias_cantidades
584
- });
574
+ if (shouldFindWarehouseSkus) {
575
+ const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce<
576
+ Record<number, BultoYCantidad[]>
577
+ >((acc, curr) => {
578
+ const tempShipmentId = curr?.idEnvioTemporal;
579
+ if (!tempShipmentId) return acc;
580
+
581
+ acc[tempShipmentId] ??= [];
582
+ acc[tempShipmentId].push(curr);
583
+
584
+ return acc;
585
+ }, {});
586
+
587
+ await Promise.all(
588
+ Object.entries(bultosYCantidadesGroupedByShipment).map(
589
+ async ([tempShipmentId, bultosYCantidades]) => {
590
+ const json_referencias_cantidades =
591
+ await this.createJsonQuantityReferencesFromLines({
592
+ idUsuario,
593
+ warehouseId,
594
+ bultosYCantidades
595
+ });
596
+
597
+ if (json_referencias_cantidades.length > 0) {
598
+ this.dataToInsert.jsonQuantityReferences.push({
599
+ id_envio: Number(tempShipmentId),
600
+ json_referencias_cantidades
601
+ });
602
+ }
585
603
  }
586
- }
587
- )
588
- );
604
+ )
605
+ );
606
+ }
589
607
 
590
608
  bultosYCantidades.forEach((each) => {
591
609
  if (!each) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.87",
3
+ "version": "0.0.89",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -230,22 +230,22 @@ export type IntegrationsService = {
230
230
 
231
231
  insertTempShipmentMultipleLines: (
232
232
  lines: DataToInsert['lines']
233
- ) => number | false;
233
+ ) => Promise<number | false>;
234
234
 
235
235
  insertTempShipmentMultipleDetails: (
236
236
  details: DataToInsert['details']
237
- ) => number | false;
237
+ ) => Promise<number | false>;
238
238
 
239
239
  insertTempShipmentMultipleContents: (
240
240
  contents: DataToInsert['contents']
241
- ) => number | false;
241
+ ) => Promise<number | false>;
242
242
 
243
243
  insertTempShipmentMultipleExternals: (
244
244
  externals: DataToInsert['externals']
245
- ) => number | false;
245
+ ) => Promise<number | false>;
246
246
  insertTempShipmentMultipleJsonQuantityReferences: (
247
247
  jsonQuantityReferences: DataToInsert['jsonQuantityReferences']
248
- ) => number | false;
248
+ ) => Promise<number | false>;
249
249
  updateTempShimpment: ({
250
250
  id_envio,
251
251
  id_usuario,
@@ -255,6 +255,16 @@ export type IntegrationsService = {
255
255
  id_usuario: number;
256
256
  id_agencia: number;
257
257
  }) => Promise<boolean>;
258
+
259
+ getDefaultIntegrationsData: ({
260
+ id_usuario,
261
+ id_integracion
262
+ }: {
263
+ id_usuario: number;
264
+ id_integracion: number;
265
+ }) => Promise<{
266
+ buscar_sku_almacen: 0 | 1;
267
+ }>;
258
268
  };
259
269
 
260
270
  export type LlmAPIService = {
@@ -264,9 +274,10 @@ export type LlmAPIService = {
264
274
  };
265
275
 
266
276
  export type WarehouseService = {
267
- getProductReferenceFromSku: (
268
- sku: string
269
- ) => Promise<{ id: number; sku: string }[]>;
277
+ getProductReferenceFromSku: (params: {
278
+ idUsuario: number;
279
+ sku: string;
280
+ }) => Promise<{ id: number; sku: string }>;
270
281
  };
271
282
 
272
283
  export type JsonReferenciasCantidades = Array<{