cardus 0.0.52 → 0.0.53

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
@@ -17,7 +17,7 @@ const moment_1 = __importDefault(require("moment"));
17
17
  const insertTempShipment_1 = require("./insertTempShipment");
18
18
  class IntegrationManager {
19
19
  constructor(params) {
20
- this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, group, isPriority }) {
20
+ this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, isPriority }) {
21
21
  const idEnvioTemporal = yield this.insertTempShipment({
22
22
  order,
23
23
  agencyId,
@@ -33,9 +33,6 @@ class IntegrationManager {
33
33
  order,
34
34
  idEnvioTemporal
35
35
  });
36
- const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
37
- if (grouped)
38
- yield this.insertTempShipmentLines({ idEnvioTemporal, group });
39
36
  return Object.assign(order, { idEnvioTemporal });
40
37
  });
41
38
  this.insertTempShipment = (_b) => __awaiter(this, [_b], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, isPriority }) {
@@ -68,8 +65,8 @@ class IntegrationManager {
68
65
  tipo_documento_holded: order.tipoDocumentoHolded || ''
69
66
  });
70
67
  };
71
- this.insertTempShipmentLines = (_c) => __awaiter(this, [_c], void 0, function* ({ idEnvioTemporal, group }) {
72
- const grouped = group.grouped === 1 || group.grouped === '1';
68
+ this.insertTempShipmentGroupLine = ({ idEnvioTemporal, group }) => {
69
+ const grouped = (group === null || group === void 0 ? void 0 : group.grouped) === 1 || (group === null || group === void 0 ? void 0 : group.grouped) === '1';
73
70
  if (grouped) {
74
71
  this.dataToInsert.lines.push({
75
72
  id_envio: idEnvioTemporal,
@@ -81,7 +78,7 @@ class IntegrationManager {
81
78
  }
82
79
  });
83
80
  }
84
- });
81
+ };
85
82
  this.services = {
86
83
  integrationsService: params.integrationsService,
87
84
  addressesService: params.addressesService,
@@ -106,7 +103,6 @@ class IntegrationManager {
106
103
  insertTempShipments(_a) {
107
104
  return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
108
105
  const user = yield this.services.usersService.obtenerUsuarioId(idUsuario);
109
- const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
110
106
  const { integrationsService, addressesService } = this.services;
111
107
  // esto hay que pasarlo ya en los parametros
112
108
  const sellerAddress = warehouseId > 0
@@ -149,7 +145,6 @@ class IntegrationManager {
149
145
  warehouseId,
150
146
  sellerAddress,
151
147
  idUsuario,
152
- group,
153
148
  isPriority: isPriorityByDefault
154
149
  });
155
150
  }),
@@ -164,7 +159,7 @@ class IntegrationManager {
164
159
  orders: successfullShipments,
165
160
  idUsuario,
166
161
  crearBulto,
167
- estaAgrupado
162
+ group
168
163
  });
169
164
  yield this.insertUserDefaultConfigurationContent({
170
165
  user,
@@ -206,15 +201,21 @@ class IntegrationManager {
206
201
  });
207
202
  }
208
203
  insertQuantityRelatedLines(_a) {
209
- return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
204
+ return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group }) {
205
+ const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
210
206
  const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
211
207
  const result = yield crearBulto({
212
208
  lineItems: { idEnvioTemporal, line },
213
209
  idUsuario
214
210
  });
215
- const { bulto, cantidad } = result;
211
+ const { bulto, cantidad, forzarAgrupamiento } = result;
216
212
  if (cantidad && bulto) {
217
- return { bulto, cantidad, idEnvioTemporal };
213
+ return {
214
+ bulto,
215
+ cantidad,
216
+ idEnvioTemporal,
217
+ forzarAgrupamiento: !!forzarAgrupamiento
218
+ };
218
219
  }
219
220
  return null;
220
221
  });
@@ -222,6 +223,9 @@ class IntegrationManager {
222
223
  orders.forEach(({ idEnvioTemporal, lineas }) => {
223
224
  if (!idEnvioTemporal)
224
225
  return;
226
+ if (grouped) {
227
+ this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
228
+ }
225
229
  lineas.forEach((line) => {
226
230
  const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
227
231
  obtenerBultosYCantidades.push(bultoPromise);
@@ -232,22 +236,28 @@ class IntegrationManager {
232
236
  bultosYCantidades.forEach((each) => {
233
237
  if (!each)
234
238
  return;
235
- const { bulto, cantidad, idEnvioTemporal } = each;
239
+ const { bulto, cantidad, idEnvioTemporal, forzarAgrupamiento } = each;
236
240
  try {
241
+ if (!grouped && forzarAgrupamiento) {
242
+ this.dataToInsert.lines.push({
243
+ id_envio: idEnvioTemporal,
244
+ bulto
245
+ });
246
+ }
237
247
  const arrayFake = Array.from({ length: Number(cantidad) });
238
248
  this.dataToInsert.details.push({
239
249
  id_envio: idEnvioTemporal,
240
250
  bulto,
241
251
  cantidad
242
252
  });
243
- arrayFake.forEach(() => {
244
- if (!estaAgrupado) {
253
+ if (!grouped && !forzarAgrupamiento) {
254
+ arrayFake.forEach(() => {
245
255
  this.dataToInsert.lines.push({
246
256
  id_envio: idEnvioTemporal,
247
257
  bulto
248
258
  });
249
- }
250
- });
259
+ });
260
+ }
251
261
  }
252
262
  catch (e) {
253
263
  console.log(e);
package/index.ts CHANGED
@@ -94,7 +94,6 @@ export class IntegrationManager {
94
94
  modificarOrdenOriginal
95
95
  }: InsertParams) {
96
96
  const user = await this.services.usersService.obtenerUsuarioId(idUsuario);
97
- const estaAgrupado = Number(group?.grouped) === 1;
98
97
  const { integrationsService, addressesService } = this.services;
99
98
  // esto hay que pasarlo ya en los parametros
100
99
  const sellerAddress =
@@ -152,7 +151,6 @@ export class IntegrationManager {
152
151
  warehouseId,
153
152
  sellerAddress,
154
153
  idUsuario,
155
- group,
156
154
  isPriority: isPriorityByDefault
157
155
  });
158
156
  },
@@ -169,7 +167,7 @@ export class IntegrationManager {
169
167
  orders: successfullShipments,
170
168
  idUsuario,
171
169
  crearBulto,
172
- estaAgrupado
170
+ group
173
171
  });
174
172
 
175
173
  await this.insertUserDefaultConfigurationContent({
@@ -245,7 +243,6 @@ export class IntegrationManager {
245
243
  warehouseId,
246
244
  sellerAddress,
247
245
  idUsuario,
248
- group,
249
246
  isPriority
250
247
  }: {
251
248
  order: ModifiedOrder;
@@ -253,7 +250,6 @@ export class IntegrationManager {
253
250
  warehouseId: number;
254
251
  sellerAddress: SellerAddress;
255
252
  idUsuario: number;
256
- group: Group;
257
253
  isPriority: IsPriority;
258
254
  }): Promise<ModifiedOrderExtended> => {
259
255
  const idEnvioTemporal = await this.insertTempShipment({
@@ -274,8 +270,6 @@ export class IntegrationManager {
274
270
  idEnvioTemporal
275
271
  });
276
272
 
277
- const grouped = Number(group?.grouped === 1);
278
- if (grouped) await this.insertTempShipmentLines({ idEnvioTemporal, group });
279
273
  return Object.assign(order, { idEnvioTemporal });
280
274
  };
281
275
 
@@ -337,15 +331,14 @@ export class IntegrationManager {
337
331
  });
338
332
  };
339
333
 
340
- insertTempShipmentLines = async ({
334
+ insertTempShipmentGroupLine = ({
341
335
  idEnvioTemporal,
342
336
  group
343
337
  }: {
344
338
  idEnvioTemporal: number;
345
339
  group: Group;
346
340
  }) => {
347
- const grouped = group.grouped === 1 || group.grouped === '1';
348
-
341
+ const grouped = group?.grouped === 1 || group?.grouped === '1';
349
342
  if (grouped) {
350
343
  this.dataToInsert.lines.push({
351
344
  id_envio: idEnvioTemporal,
@@ -363,19 +356,22 @@ export class IntegrationManager {
363
356
  orders,
364
357
  idUsuario,
365
358
  crearBulto,
366
- estaAgrupado
359
+ group
367
360
  }: {
368
361
  orders: ModifiedOrderExtended[];
369
362
  idUsuario: number;
370
363
  crearBulto: CrearBulto;
371
- estaAgrupado: boolean;
364
+ group: Group;
372
365
  }) {
373
366
  type BultoYCantidad = {
374
367
  bulto: Bulto['bulto'];
375
368
  cantidad: Bulto['cantidad'];
376
369
  idEnvioTemporal: number;
370
+ forzarAgrupamiento: boolean;
377
371
  };
378
372
 
373
+ const grouped = Number(group?.grouped === 1);
374
+
379
375
  const createBultoFromLine = async ({
380
376
  line,
381
377
  idEnvioTemporal
@@ -387,10 +383,15 @@ export class IntegrationManager {
387
383
  lineItems: { idEnvioTemporal, line },
388
384
  idUsuario
389
385
  });
390
- const { bulto, cantidad } = result;
386
+ const { bulto, cantidad, forzarAgrupamiento } = result;
391
387
 
392
388
  if (cantidad && bulto) {
393
- return { bulto, cantidad, idEnvioTemporal };
389
+ return {
390
+ bulto,
391
+ cantidad,
392
+ idEnvioTemporal,
393
+ forzarAgrupamiento: !!forzarAgrupamiento
394
+ };
394
395
  }
395
396
  return null;
396
397
  };
@@ -399,6 +400,11 @@ export class IntegrationManager {
399
400
 
400
401
  orders.forEach(({ idEnvioTemporal, lineas }) => {
401
402
  if (!idEnvioTemporal) return;
403
+
404
+ if (grouped) {
405
+ this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
406
+ }
407
+
402
408
  lineas.forEach((line) => {
403
409
  const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
404
410
  obtenerBultosYCantidades.push(bultoPromise);
@@ -410,8 +416,15 @@ export class IntegrationManager {
410
416
 
411
417
  bultosYCantidades.forEach((each) => {
412
418
  if (!each) return;
413
- const { bulto, cantidad, idEnvioTemporal } = each;
419
+ const { bulto, cantidad, idEnvioTemporal, forzarAgrupamiento } = each;
414
420
  try {
421
+ if (!grouped && forzarAgrupamiento) {
422
+ this.dataToInsert.lines.push({
423
+ id_envio: idEnvioTemporal,
424
+ bulto
425
+ });
426
+ }
427
+
415
428
  const arrayFake = Array.from({ length: Number(cantidad) });
416
429
 
417
430
  this.dataToInsert.details.push({
@@ -420,14 +433,14 @@ export class IntegrationManager {
420
433
  cantidad
421
434
  });
422
435
 
423
- arrayFake.forEach(() => {
424
- if (!estaAgrupado) {
436
+ if (!grouped && !forzarAgrupamiento) {
437
+ arrayFake.forEach(() => {
425
438
  this.dataToInsert.lines.push({
426
439
  id_envio: idEnvioTemporal,
427
440
  bulto
428
441
  });
429
- }
430
- });
442
+ });
443
+ }
431
444
  } catch (e) {
432
445
  console.log(e);
433
446
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -93,6 +93,7 @@ export type Bulto = {
93
93
  nombre_producto: string | null;
94
94
  };
95
95
  cantidad: number;
96
+ forzarAgrupamiento: boolean;
96
97
  };
97
98
 
98
99
  export type ModifiedOrder = {
@@ -128,7 +129,7 @@ type FetchAllOrders = () => Promise<OriginalOrder[]>;
128
129
  export type CrearBulto = (params: {
129
130
  lineItems: { idEnvioTemporal: number; line: AnyObject };
130
131
  idUsuario: number;
131
- }) => Promise<Bulto | { bulto: null; cantidad: 0 }>;
132
+ }) => Promise<Bulto>;
132
133
 
133
134
  type ModificarOrdenOriginal = (param: {
134
135
  originalOrder: OriginalOrder;