cardus 0.0.51 → 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
@@ -143,12 +139,12 @@ class IntegrationManager {
143
139
  defaultAgencyId: agencyId,
144
140
  userId: idUsuario,
145
141
  integrationId: this.integrationType,
146
- tempShipmentData: parsedOrder
142
+ tempShipmentData: parsedOrder,
143
+ sellerAddress
147
144
  }),
148
145
  warehouseId,
149
146
  sellerAddress,
150
147
  idUsuario,
151
- group,
152
148
  isPriority: isPriorityByDefault
153
149
  });
154
150
  }),
@@ -163,7 +159,7 @@ class IntegrationManager {
163
159
  orders: successfullShipments,
164
160
  idUsuario,
165
161
  crearBulto,
166
- estaAgrupado
162
+ group
167
163
  });
168
164
  yield this.insertUserDefaultConfigurationContent({
169
165
  user,
@@ -205,15 +201,21 @@ class IntegrationManager {
205
201
  });
206
202
  }
207
203
  insertQuantityRelatedLines(_a) {
208
- 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);
209
206
  const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
210
207
  const result = yield crearBulto({
211
208
  lineItems: { idEnvioTemporal, line },
212
209
  idUsuario
213
210
  });
214
- const { bulto, cantidad } = result;
211
+ const { bulto, cantidad, forzarAgrupamiento } = result;
215
212
  if (cantidad && bulto) {
216
- return { bulto, cantidad, idEnvioTemporal };
213
+ return {
214
+ bulto,
215
+ cantidad,
216
+ idEnvioTemporal,
217
+ forzarAgrupamiento: !!forzarAgrupamiento
218
+ };
217
219
  }
218
220
  return null;
219
221
  });
@@ -221,6 +223,9 @@ class IntegrationManager {
221
223
  orders.forEach(({ idEnvioTemporal, lineas }) => {
222
224
  if (!idEnvioTemporal)
223
225
  return;
226
+ if (grouped) {
227
+ this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
228
+ }
224
229
  lineas.forEach((line) => {
225
230
  const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
226
231
  obtenerBultosYCantidades.push(bultoPromise);
@@ -231,22 +236,28 @@ class IntegrationManager {
231
236
  bultosYCantidades.forEach((each) => {
232
237
  if (!each)
233
238
  return;
234
- const { bulto, cantidad, idEnvioTemporal } = each;
239
+ const { bulto, cantidad, idEnvioTemporal, forzarAgrupamiento } = each;
235
240
  try {
241
+ if (!grouped && forzarAgrupamiento) {
242
+ this.dataToInsert.lines.push({
243
+ id_envio: idEnvioTemporal,
244
+ bulto
245
+ });
246
+ }
236
247
  const arrayFake = Array.from({ length: Number(cantidad) });
237
248
  this.dataToInsert.details.push({
238
249
  id_envio: idEnvioTemporal,
239
250
  bulto,
240
251
  cantidad
241
252
  });
242
- arrayFake.forEach(() => {
243
- if (!estaAgrupado) {
253
+ if (!grouped && !forzarAgrupamiento) {
254
+ arrayFake.forEach(() => {
244
255
  this.dataToInsert.lines.push({
245
256
  id_envio: idEnvioTemporal,
246
257
  bulto
247
258
  });
248
- }
249
- });
259
+ });
260
+ }
250
261
  }
251
262
  catch (e) {
252
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 =
@@ -146,12 +145,12 @@ export class IntegrationManager {
146
145
  defaultAgencyId: agencyId,
147
146
  userId: idUsuario,
148
147
  integrationId: this.integrationType,
149
- tempShipmentData: parsedOrder
148
+ tempShipmentData: parsedOrder,
149
+ sellerAddress
150
150
  }),
151
151
  warehouseId,
152
152
  sellerAddress,
153
153
  idUsuario,
154
- group,
155
154
  isPriority: isPriorityByDefault
156
155
  });
157
156
  },
@@ -168,7 +167,7 @@ export class IntegrationManager {
168
167
  orders: successfullShipments,
169
168
  idUsuario,
170
169
  crearBulto,
171
- estaAgrupado
170
+ group
172
171
  });
173
172
 
174
173
  await this.insertUserDefaultConfigurationContent({
@@ -244,7 +243,6 @@ export class IntegrationManager {
244
243
  warehouseId,
245
244
  sellerAddress,
246
245
  idUsuario,
247
- group,
248
246
  isPriority
249
247
  }: {
250
248
  order: ModifiedOrder;
@@ -252,7 +250,6 @@ export class IntegrationManager {
252
250
  warehouseId: number;
253
251
  sellerAddress: SellerAddress;
254
252
  idUsuario: number;
255
- group: Group;
256
253
  isPriority: IsPriority;
257
254
  }): Promise<ModifiedOrderExtended> => {
258
255
  const idEnvioTemporal = await this.insertTempShipment({
@@ -273,8 +270,6 @@ export class IntegrationManager {
273
270
  idEnvioTemporal
274
271
  });
275
272
 
276
- const grouped = Number(group?.grouped === 1);
277
- if (grouped) await this.insertTempShipmentLines({ idEnvioTemporal, group });
278
273
  return Object.assign(order, { idEnvioTemporal });
279
274
  };
280
275
 
@@ -336,15 +331,14 @@ export class IntegrationManager {
336
331
  });
337
332
  };
338
333
 
339
- insertTempShipmentLines = async ({
334
+ insertTempShipmentGroupLine = ({
340
335
  idEnvioTemporal,
341
336
  group
342
337
  }: {
343
338
  idEnvioTemporal: number;
344
339
  group: Group;
345
340
  }) => {
346
- const grouped = group.grouped === 1 || group.grouped === '1';
347
-
341
+ const grouped = group?.grouped === 1 || group?.grouped === '1';
348
342
  if (grouped) {
349
343
  this.dataToInsert.lines.push({
350
344
  id_envio: idEnvioTemporal,
@@ -362,19 +356,22 @@ export class IntegrationManager {
362
356
  orders,
363
357
  idUsuario,
364
358
  crearBulto,
365
- estaAgrupado
359
+ group
366
360
  }: {
367
361
  orders: ModifiedOrderExtended[];
368
362
  idUsuario: number;
369
363
  crearBulto: CrearBulto;
370
- estaAgrupado: boolean;
364
+ group: Group;
371
365
  }) {
372
366
  type BultoYCantidad = {
373
367
  bulto: Bulto['bulto'];
374
368
  cantidad: Bulto['cantidad'];
375
369
  idEnvioTemporal: number;
370
+ forzarAgrupamiento: boolean;
376
371
  };
377
372
 
373
+ const grouped = Number(group?.grouped === 1);
374
+
378
375
  const createBultoFromLine = async ({
379
376
  line,
380
377
  idEnvioTemporal
@@ -386,10 +383,15 @@ export class IntegrationManager {
386
383
  lineItems: { idEnvioTemporal, line },
387
384
  idUsuario
388
385
  });
389
- const { bulto, cantidad } = result;
386
+ const { bulto, cantidad, forzarAgrupamiento } = result;
390
387
 
391
388
  if (cantidad && bulto) {
392
- return { bulto, cantidad, idEnvioTemporal };
389
+ return {
390
+ bulto,
391
+ cantidad,
392
+ idEnvioTemporal,
393
+ forzarAgrupamiento: !!forzarAgrupamiento
394
+ };
393
395
  }
394
396
  return null;
395
397
  };
@@ -398,6 +400,11 @@ export class IntegrationManager {
398
400
 
399
401
  orders.forEach(({ idEnvioTemporal, lineas }) => {
400
402
  if (!idEnvioTemporal) return;
403
+
404
+ if (grouped) {
405
+ this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
406
+ }
407
+
401
408
  lineas.forEach((line) => {
402
409
  const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
403
410
  obtenerBultosYCantidades.push(bultoPromise);
@@ -409,8 +416,15 @@ export class IntegrationManager {
409
416
 
410
417
  bultosYCantidades.forEach((each) => {
411
418
  if (!each) return;
412
- const { bulto, cantidad, idEnvioTemporal } = each;
419
+ const { bulto, cantidad, idEnvioTemporal, forzarAgrupamiento } = each;
413
420
  try {
421
+ if (!grouped && forzarAgrupamiento) {
422
+ this.dataToInsert.lines.push({
423
+ id_envio: idEnvioTemporal,
424
+ bulto
425
+ });
426
+ }
427
+
414
428
  const arrayFake = Array.from({ length: Number(cantidad) });
415
429
 
416
430
  this.dataToInsert.details.push({
@@ -419,14 +433,14 @@ export class IntegrationManager {
419
433
  cantidad
420
434
  });
421
435
 
422
- arrayFake.forEach(() => {
423
- if (!estaAgrupado) {
436
+ if (!grouped && !forzarAgrupamiento) {
437
+ arrayFake.forEach(() => {
424
438
  this.dataToInsert.lines.push({
425
439
  id_envio: idEnvioTemporal,
426
440
  bulto
427
441
  });
428
- }
429
- });
442
+ });
443
+ }
430
444
  } catch (e) {
431
445
  console.log(e);
432
446
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.51",
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;
@@ -334,6 +335,7 @@ export type GetAgencyIdForTempShipment = (params: {
334
335
  userId: number;
335
336
  integrationId: number;
336
337
  tempShipmentData: ModifiedOrder;
338
+ sellerAddress: SellerAddress;
337
339
  }) => Promise<number>;
338
340
 
339
341
  export type ExecutionManager = {