cardus 0.0.39 → 0.0.40

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
@@ -118,7 +118,6 @@ class IntegrationManager {
118
118
  type: this.type
119
119
  });
120
120
  const checkIsPriorityByDefault = () => __awaiter(this, void 0, void 0, function* () {
121
- // TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
122
121
  const usuariosGeneiPriority = yield this.services.customizationService.getUsersWithSection(8);
123
122
  const esPotencialmentePriority = usuariosGeneiPriority.some((seccion) => seccion.id_usuario === user.id_usuario ||
124
123
  seccion.tipo_cliente === user.tipo_cliente ||
@@ -204,27 +203,30 @@ class IntegrationManager {
204
203
  }
205
204
  insertQuantityRelatedLines(_a) {
206
205
  return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
207
- const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
208
- if (!idEnvioTemporal)
206
+ const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
207
+ const { bulto, cantidad = 0 } = yield crearBulto({
208
+ lineItems: { idEnvioTemporal, line },
209
+ idUsuario
210
+ });
211
+ if (cantidad === 0)
209
212
  return null;
210
- return yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
211
- const { bulto, cantidad = 0 } = yield crearBulto({
212
- lineItems: { idEnvioTemporal, line },
213
- idUsuario
214
- });
215
- if (cantidad === 0)
216
- return null;
217
- return { bulto, cantidad, idEnvioTemporal };
218
- })));
219
- }));
220
- const bultosYCantidades = (yield new Promise((res) => __awaiter(this, void 0, void 0, function* () {
221
- const bultosYCantidadesAnidados = yield Promise.all(obtenerBultosYCantidades);
222
- const bultosYCantidades = bultosYCantidadesAnidados
223
- .flat()
224
- .filter(Boolean);
225
- res(bultosYCantidades);
226
- })));
227
- bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
213
+ return { bulto, cantidad, idEnvioTemporal };
214
+ });
215
+ const obtenerBultosYCantidades = [];
216
+ orders.forEach(({ idEnvioTemporal, lineas }) => {
217
+ if (!idEnvioTemporal)
218
+ return;
219
+ lineas.forEach((line) => {
220
+ const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
221
+ obtenerBultosYCantidades.push(bultoPromise);
222
+ });
223
+ });
224
+ let bultosYCantidades = yield Promise.all(obtenerBultosYCantidades);
225
+ bultosYCantidades = bultosYCantidades.filter(Boolean);
226
+ bultosYCantidades.forEach((each) => {
227
+ if (!each)
228
+ return;
229
+ const { bulto, cantidad, idEnvioTemporal } = each;
228
230
  try {
229
231
  const arrayFake = Array.from({ length: Number(cantidad) });
230
232
  arrayFake.forEach(() => {
package/index.ts CHANGED
@@ -23,7 +23,9 @@ import {
23
23
  GetAgencyIdForTempShipment,
24
24
  IsPriority,
25
25
  CustomizationService,
26
- DataToInsert
26
+ DataToInsert,
27
+ InsertContentShipmentLine,
28
+ Bulto
27
29
  } from './types';
28
30
 
29
31
  const dataToInsert: DataToInsert = {
@@ -103,11 +105,14 @@ export class IntegrationManager {
103
105
  });
104
106
 
105
107
  const checkIsPriorityByDefault = async () => {
106
- // TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
107
108
  const usuariosGeneiPriority =
108
109
  await this.services.customizationService.getUsersWithSection(8);
109
110
  const esPotencialmentePriority = usuariosGeneiPriority.some(
110
- (seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any }) =>
111
+ (seccion: {
112
+ id_usuario: number | string;
113
+ tipo_cliente: number;
114
+ id_comercial: number | string;
115
+ }) =>
111
116
  seccion.id_usuario === user.id_usuario ||
112
117
  seccion.tipo_cliente === user.tipo_cliente ||
113
118
  seccion.id_comercial === user.id_comercial
@@ -204,7 +209,7 @@ export class IntegrationManager {
204
209
  });
205
210
  };
206
211
 
207
- let userConfiguration: UserDefaultConfigurationContent[] | any = null;
212
+ let userConfiguration: UserDefaultConfigurationContent[] | null = null;
208
213
  const userSavedData =
209
214
  (await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
210
215
  [];
@@ -356,35 +361,43 @@ export class IntegrationManager {
356
361
  crearBulto: CrearBulto;
357
362
  estaAgrupado: boolean;
358
363
  }) {
359
- const obtenerBultosYCantidades = orders.map(
360
- async ({ idEnvioTemporal, lineas }) => {
361
- if (!idEnvioTemporal) return null;
362
- return await Promise.all(
363
- lineas.map(async (line) => {
364
- const { bulto, cantidad = 0 } = await crearBulto({
365
- lineItems: { idEnvioTemporal, line },
366
- idUsuario
367
- });
368
- if (cantidad === 0) return null;
369
- return { bulto, cantidad, idEnvioTemporal };
370
- })
371
- );
372
- }
373
- );
364
+ type BultoYCantidad = {
365
+ bulto: Bulto['bulto'];
366
+ cantidad: Bulto['cantidad'];
367
+ idEnvioTemporal: number;
368
+ };
374
369
 
375
- const bultosYCantidades = (await new Promise(async (res) => {
376
- const bultosYCantidadesAnidados = await Promise.all(
377
- obtenerBultosYCantidades
378
- );
370
+ const createBultoFromLine = async ({
371
+ line,
372
+ idEnvioTemporal
373
+ }: {
374
+ line: InsertContentShipmentLine;
375
+ idEnvioTemporal: number;
376
+ }): Promise<BultoYCantidad | null> => {
377
+ const { bulto, cantidad = 0 } = await crearBulto({
378
+ lineItems: { idEnvioTemporal, line },
379
+ idUsuario
380
+ });
381
+ if (cantidad === 0) return null;
382
+ return { bulto, cantidad, idEnvioTemporal };
383
+ };
379
384
 
380
- const bultosYCantidades = bultosYCantidadesAnidados
381
- .flat()
382
- .filter(Boolean);
385
+ const obtenerBultosYCantidades: Array<Promise<BultoYCantidad | null>> = [];
386
+
387
+ orders.forEach(({ idEnvioTemporal, lineas }) => {
388
+ if (!idEnvioTemporal) return;
389
+ lineas.forEach((line) => {
390
+ const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
391
+ obtenerBultosYCantidades.push(bultoPromise);
392
+ });
393
+ });
383
394
 
384
- res(bultosYCantidades);
385
- })) as Array<any>;
395
+ let bultosYCantidades = await Promise.all(obtenerBultosYCantidades);
396
+ bultosYCantidades = bultosYCantidades.filter(Boolean);
386
397
 
387
- bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
398
+ bultosYCantidades.forEach((each) => {
399
+ if (!each) return;
400
+ const { bulto, cantidad, idEnvioTemporal } = each;
388
401
  try {
389
402
  const arrayFake = Array.from({ length: Number(cantidad) });
390
403
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -77,7 +77,7 @@ export type Bulto = {
77
77
  };
78
78
 
79
79
  export type ModifiedOrder = {
80
- lineas: Array<AnyObject>;
80
+ lineas: Array<InsertContentShipmentLine>;
81
81
  codigoPaisLLegada: string | undefined;
82
82
  codigoPostalLLegada: string | undefined;
83
83
  primerApellidoLLegada: string | undefined;
@@ -328,7 +328,7 @@ export type DataToInsert = {
328
328
  externals: InsertContentShipmentExternal[];
329
329
  };
330
330
 
331
- type InsertContentShipmentLine = {
331
+ export type InsertContentShipmentLine = {
332
332
  id_envio: number;
333
333
  bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
334
334
  };