cardus 0.0.38 → 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
@@ -19,7 +19,7 @@ const dataToInsert = {
19
19
  lines: [],
20
20
  contents: [],
21
21
  details: [],
22
- externals: [],
22
+ externals: []
23
23
  };
24
24
  class IntegrationManager {
25
25
  constructor(params) {
@@ -30,7 +30,7 @@ class IntegrationManager {
30
30
  warehouseId,
31
31
  sellerAddress,
32
32
  idUsuario,
33
- isPriority,
33
+ isPriority
34
34
  });
35
35
  if (!idEnvioTemporal)
36
36
  throw new Error('Temp shipments could not be created');
@@ -94,7 +94,7 @@ class IntegrationManager {
94
94
  countriesService: params.countriesService,
95
95
  configurationService: params.configurationService,
96
96
  usersService: params.usersService,
97
- customizationService: params.customizationService,
97
+ customizationService: params.customizationService
98
98
  };
99
99
  this.shipmentType = params.shipmentType;
100
100
  this.type = params.type;
@@ -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 ||
@@ -143,13 +142,13 @@ class IntegrationManager {
143
142
  defaultAgencyId: agencyId,
144
143
  userId: idUsuario,
145
144
  integrationId: this.shipmentType,
146
- tempShipmentData: parsedOrder,
145
+ tempShipmentData: parsedOrder
147
146
  }),
148
147
  warehouseId,
149
148
  sellerAddress,
150
149
  idUsuario,
151
150
  group,
152
- isPriority: isPriorityByDefault,
151
+ isPriority: isPriorityByDefault
153
152
  });
154
153
  }),
155
154
  regularExecutionTime: 8000, // ms
@@ -186,7 +185,8 @@ class IntegrationManager {
186
185
  });
187
186
  };
188
187
  let userConfiguration = null;
189
- const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
188
+ const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
189
+ [];
190
190
  if (userSavedData.length > 0) {
191
191
  userConfiguration = userSavedData;
192
192
  }
@@ -195,7 +195,7 @@ class IntegrationManager {
195
195
  userConfiguration = userFakeData;
196
196
  }
197
197
  if (userConfiguration && userConfiguration !== null) {
198
- tempShimpmentIds.forEach(tempShimpmentId => {
198
+ tempShimpmentIds.forEach((tempShimpmentId) => {
199
199
  insert(userConfiguration, tempShimpmentId);
200
200
  });
201
201
  }
@@ -203,27 +203,30 @@ class IntegrationManager {
203
203
  }
204
204
  insertQuantityRelatedLines(_a) {
205
205
  return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
206
- const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
207
- 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)
208
212
  return null;
209
- return yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
210
- const { bulto, cantidad = 0 } = yield crearBulto({
211
- lineItems: { idEnvioTemporal, line },
212
- idUsuario
213
- });
214
- if (cantidad === 0)
215
- return null;
216
- return { bulto, cantidad, idEnvioTemporal };
217
- })));
218
- }));
219
- const bultosYCantidades = (yield new Promise((res) => __awaiter(this, void 0, void 0, function* () {
220
- const bultosYCantidadesAnidados = yield Promise.all(obtenerBultosYCantidades);
221
- const bultosYCantidades = bultosYCantidadesAnidados
222
- .flat()
223
- .filter(Boolean);
224
- res(bultosYCantidades);
225
- })));
226
- 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;
227
230
  try {
228
231
  const arrayFake = Array.from({ length: Number(cantidad) });
229
232
  arrayFake.forEach(() => {
package/index.ts CHANGED
@@ -24,14 +24,16 @@ import {
24
24
  IsPriority,
25
25
  CustomizationService,
26
26
  DataToInsert,
27
+ InsertContentShipmentLine,
28
+ Bulto
27
29
  } from './types';
28
30
 
29
31
  const dataToInsert: DataToInsert = {
30
32
  lines: [],
31
33
  contents: [],
32
34
  details: [],
33
- externals: [],
34
- }
35
+ externals: []
36
+ };
35
37
 
36
38
  interface Services {
37
39
  integrationsService: IntegrationsService;
@@ -69,7 +71,7 @@ export class IntegrationManager {
69
71
  countriesService: params.countriesService,
70
72
  configurationService: params.configurationService,
71
73
  usersService: params.usersService,
72
- customizationService: params.customizationService,
74
+ customizationService: params.customizationService
73
75
  };
74
76
 
75
77
  this.shipmentType = params.shipmentType;
@@ -103,10 +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
- const usuariosGeneiPriority = await this.services.customizationService.getUsersWithSection(8);
108
+ const usuariosGeneiPriority =
109
+ await this.services.customizationService.getUsersWithSection(8);
108
110
  const esPotencialmentePriority = usuariosGeneiPriority.some(
109
- (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
+ }) =>
110
116
  seccion.id_usuario === user.id_usuario ||
111
117
  seccion.tipo_cliente === user.tipo_cliente ||
112
118
  seccion.id_comercial === user.id_comercial
@@ -119,7 +125,7 @@ export class IntegrationManager {
119
125
  }
120
126
  };
121
127
 
122
- const isPriorityByDefault = await checkIsPriorityByDefault()
128
+ const isPriorityByDefault = await checkIsPriorityByDefault();
123
129
 
124
130
  const insertOrdersResult = await new this.executionManager({
125
131
  arrayParams: allOrders,
@@ -134,13 +140,13 @@ export class IntegrationManager {
134
140
  defaultAgencyId: agencyId,
135
141
  userId: idUsuario,
136
142
  integrationId: this.shipmentType,
137
- tempShipmentData: parsedOrder,
143
+ tempShipmentData: parsedOrder
138
144
  }),
139
145
  warehouseId,
140
146
  sellerAddress,
141
147
  idUsuario,
142
148
  group,
143
- isPriority: isPriorityByDefault,
149
+ isPriority: isPriorityByDefault
144
150
  });
145
151
  },
146
152
  regularExecutionTime: 8000, // ms
@@ -165,10 +171,18 @@ export class IntegrationManager {
165
171
  (successfullShipment) => successfullShipment.idEnvioTemporal
166
172
  )
167
173
  });
168
- await integrationsService.insertTempShipmentMultipleLines(dataToInsert.lines);
169
- await integrationsService.insertTempShipmentMultipleDetails(dataToInsert.details);
170
- await integrationsService.insertTempShipmentMultipleContents(dataToInsert.contents);
171
- await integrationsService.insertTempShipmentMultipleExternals(dataToInsert.externals);
174
+ await integrationsService.insertTempShipmentMultipleLines(
175
+ dataToInsert.lines
176
+ );
177
+ await integrationsService.insertTempShipmentMultipleDetails(
178
+ dataToInsert.details
179
+ );
180
+ await integrationsService.insertTempShipmentMultipleContents(
181
+ dataToInsert.contents
182
+ );
183
+ await integrationsService.insertTempShipmentMultipleExternals(
184
+ dataToInsert.externals
185
+ );
172
186
 
173
187
  return { filteredOrders, insertedTempShipments: successfullShipments };
174
188
  }
@@ -177,34 +191,31 @@ export class IntegrationManager {
177
191
  user,
178
192
  tempShimpmentIds
179
193
  }: {
180
- user: { id_usuario: number, dni: string };
194
+ user: { id_usuario: number; dni: string };
181
195
  tempShimpmentIds: number[];
182
196
  }) {
183
- const idUsuario = user.id_usuario
184
- const { configurationService } =
185
- this.services;
197
+ const idUsuario = user.id_usuario;
198
+ const { configurationService } = this.services;
186
199
 
187
200
  const insert = (
188
201
  data: UserDefaultConfigurationContent[],
189
202
  tempShimpmentId: number
190
203
  ) => {
191
204
  data.forEach((tempContent) => {
192
- dataToInsert.contents.push({
193
- ...tempContent,
194
- id_envio: tempShimpmentId
195
- });
196
- })
205
+ dataToInsert.contents.push({
206
+ ...tempContent,
207
+ id_envio: tempShimpmentId
208
+ });
209
+ });
197
210
  };
198
211
 
199
- let userConfiguration: UserDefaultConfigurationContent[] | any = null;
212
+ let userConfiguration: UserDefaultConfigurationContent[] | null = null;
200
213
  const userSavedData =
201
- (await configurationService.getDefaultProformaConfiguration(
202
- idUsuario
203
- )) || [];
204
- if (userSavedData.length > 0){
214
+ (await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
215
+ [];
216
+ if (userSavedData.length > 0) {
205
217
  userConfiguration = userSavedData;
206
- }
207
- else {
218
+ } else {
208
219
  const userFakeData =
209
220
  configurationService.getFakeDefaultProformaConfiguration(
210
221
  idUsuario,
@@ -212,10 +223,10 @@ export class IntegrationManager {
212
223
  );
213
224
  userConfiguration = userFakeData;
214
225
  }
215
- if (userConfiguration && userConfiguration !== null){
216
- tempShimpmentIds.forEach(tempShimpmentId => {
226
+ if (userConfiguration && userConfiguration !== null) {
227
+ tempShimpmentIds.forEach((tempShimpmentId) => {
217
228
  insert(userConfiguration, tempShimpmentId);
218
- })
229
+ });
219
230
  }
220
231
  }
221
232
 
@@ -234,7 +245,7 @@ export class IntegrationManager {
234
245
  sellerAddress: SellerAddress;
235
246
  idUsuario: number;
236
247
  group: Group;
237
- isPriority: IsPriority
248
+ isPriority: IsPriority;
238
249
  }): Promise<ModifiedOrderExtended> => {
239
250
  const idEnvioTemporal = await this.insertTempShipment({
240
251
  order,
@@ -242,7 +253,7 @@ export class IntegrationManager {
242
253
  warehouseId,
243
254
  sellerAddress,
244
255
  idUsuario,
245
- isPriority,
256
+ isPriority
246
257
  });
247
258
 
248
259
  if (!idEnvioTemporal)
@@ -272,7 +283,7 @@ export class IntegrationManager {
272
283
  warehouseId: number;
273
284
  sellerAddress: SellerAddress;
274
285
  idUsuario: number;
275
- isPriority: IsPriority
286
+ isPriority: IsPriority;
276
287
  }) => {
277
288
  const tempShipmentData = await cookTempShipment({
278
289
  order,
@@ -301,7 +312,6 @@ export class IntegrationManager {
301
312
  order: ModifiedOrder;
302
313
  idEnvioTemporal: number;
303
314
  }): undefined => {
304
-
305
315
  dataToInsert.externals.push({
306
316
  id_envio_temporal_usuario: idEnvioTemporal,
307
317
  codigo_envio_externo: order.codigoEnvioExterno,
@@ -315,7 +325,7 @@ export class IntegrationManager {
315
325
  marketplaceId: order.marketplaceId,
316
326
  id_documento_holded: order.idDocumentoHolded,
317
327
  tipo_documento_holded: order.tipoDocumentoHolded || ''
318
- })
328
+ });
319
329
  };
320
330
 
321
331
  insertTempShipmentLines = async ({
@@ -336,7 +346,7 @@ export class IntegrationManager {
336
346
  ancho: group.width,
337
347
  largo: group.length
338
348
  }
339
- })
349
+ });
340
350
  }
341
351
  };
342
352
 
@@ -351,36 +361,43 @@ export class IntegrationManager {
351
361
  crearBulto: CrearBulto;
352
362
  estaAgrupado: boolean;
353
363
  }) {
364
+ type BultoYCantidad = {
365
+ bulto: Bulto['bulto'];
366
+ cantidad: Bulto['cantidad'];
367
+ idEnvioTemporal: number;
368
+ };
354
369
 
355
- const obtenerBultosYCantidades = orders.map(
356
- async ({ idEnvioTemporal, lineas }) => {
357
- if (!idEnvioTemporal) return null;
358
- return await Promise.all(
359
- lineas.map(async (line) => {
360
- const { bulto, cantidad = 0 } = await crearBulto({
361
- lineItems: { idEnvioTemporal, line },
362
- idUsuario
363
- });
364
- if (cantidad === 0) return null;
365
- return { bulto, cantidad, idEnvioTemporal };
366
- })
367
- );
368
- }
369
- );
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
+ };
370
384
 
371
- const bultosYCantidades = (await new Promise(async (res) => {
372
- const bultosYCantidadesAnidados = await Promise.all(
373
- obtenerBultosYCantidades
374
- );
385
+ const obtenerBultosYCantidades: Array<Promise<BultoYCantidad | null>> = [];
375
386
 
376
- const bultosYCantidades = bultosYCantidadesAnidados
377
- .flat()
378
- .filter(Boolean);
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
+ });
379
394
 
380
- res(bultosYCantidades);
381
- })) as Array<any>;
395
+ let bultosYCantidades = await Promise.all(obtenerBultosYCantidades);
396
+ bultosYCantidades = bultosYCantidades.filter(Boolean);
382
397
 
383
- bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
398
+ bultosYCantidades.forEach((each) => {
399
+ if (!each) return;
400
+ const { bulto, cantidad, idEnvioTemporal } = each;
384
401
  try {
385
402
  const arrayFake = Array.from({ length: Number(cantidad) });
386
403
 
@@ -396,10 +413,9 @@ export class IntegrationManager {
396
413
  bulto
397
414
  });
398
415
  });
399
-
400
416
  } catch (e) {
401
417
  console.log(e);
402
418
  }
403
419
  });
404
420
  }
405
- }
421
+ }
@@ -30,7 +30,7 @@ export const cookTempShipment = async ({
30
30
  idUsuario: number;
31
31
  findNextPickupDate: FindNextPickupDate;
32
32
  countriesService: CountriesService;
33
- isPriority: IsPriority
33
+ isPriority: IsPriority;
34
34
  }): Promise<Shipment> => {
35
35
  let zonaLLegada = {};
36
36
  if (order.codigoPaisLLegada)
@@ -54,7 +54,6 @@ export const cookTempShipment = async ({
54
54
  mail_salida: sellerAddress.mail
55
55
  });
56
56
 
57
-
58
57
  const setUbicacionComprador = async (order: ModifiedOrder) => {
59
58
  type CompradorLocation = {
60
59
  pais_llegada: string | null;
@@ -62,7 +61,6 @@ export const cookTempShipment = async ({
62
61
  id_zona_llegada: string | null;
63
62
  };
64
63
 
65
-
66
64
  const compradorLocation: CompradorLocation = {
67
65
  pais_llegada: null,
68
66
  provincia_llegada: null,
@@ -93,7 +91,6 @@ export const cookTempShipment = async ({
93
91
  return compradorLocation;
94
92
  };
95
93
 
96
-
97
94
  const setDatosComprador = async (order: ModifiedOrder) => ({
98
95
  nom_ape_llegada: order.primerApellidoLLegada
99
96
  ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
@@ -113,12 +110,10 @@ export const cookTempShipment = async ({
113
110
  mail_llegada: order.emailLLegada || 'no informado'
114
111
  });
115
112
 
116
-
117
113
  const setReembolso = (order: ModifiedOrder) => {
118
114
  return { cantidad_contrareembolso: order.cantidadContrareembolso };
119
115
  };
120
116
 
121
-
122
117
  const setFechas = async (order: ModifiedOrder) => {
123
118
  const date = moment().format('YYYY-MM-DD');
124
119
  const beginHour = '09:00';
@@ -179,8 +174,7 @@ export const cookTempShipment = async ({
179
174
  ...stepResult,
180
175
  priority: isPriority
181
176
  };
182
-
183
177
  }, {})) as Shipment;
184
178
 
185
179
  return dataInsert;
186
- };
180
+ };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "scripts": {
8
8
  "build": "rm -rf dist && tsc --build",
9
- "prepublishOnly": "npm run build",
9
+ "prepublishOnly": "npm run format && npm run build",
10
10
  "test": "jest",
11
11
  "lint": "eslint --ignore-path .eslintignore --ext .js,.ts && npm run format",
12
12
  "format": "prettier --config .prettierrc './**/*.ts' --write"
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;
@@ -182,13 +182,21 @@ export type IntegrationsService = {
182
182
  params: UserDefaultConfigurationContent & { id_envio: number }
183
183
  ) => Promise<number | false>;
184
184
 
185
- insertTempShipmentMultipleLines: (lines: DataToInsert["lines"]) => number | false;
185
+ insertTempShipmentMultipleLines: (
186
+ lines: DataToInsert['lines']
187
+ ) => number | false;
186
188
 
187
- insertTempShipmentMultipleDetails: (details: DataToInsert["details"]) => number | false;
189
+ insertTempShipmentMultipleDetails: (
190
+ details: DataToInsert['details']
191
+ ) => number | false;
188
192
 
189
- insertTempShipmentMultipleContents: (contents: DataToInsert["contents"]) => number | false;
193
+ insertTempShipmentMultipleContents: (
194
+ contents: DataToInsert['contents']
195
+ ) => number | false;
190
196
 
191
- insertTempShipmentMultipleExternals: (externals: DataToInsert["externals"]) => number | false;
197
+ insertTempShipmentMultipleExternals: (
198
+ externals: DataToInsert['externals']
199
+ ) => number | false;
192
200
  };
193
201
 
194
202
  export type SellerAddress = {
@@ -269,7 +277,7 @@ export type ConfigurationService = {
269
277
  ) => UserDefaultConfigurationContent[];
270
278
  };
271
279
 
272
- export type IsPriority = number
280
+ export type IsPriority = number;
273
281
 
274
282
  export type UsersService = {
275
283
  obtenerUsuarioId: (id_usuario: number) => Promise<User>;
@@ -277,7 +285,7 @@ export type UsersService = {
277
285
 
278
286
  export type CustomizationService = {
279
287
  getUsersWithSection: (seccion: number) => Promise<User[]>;
280
- }
288
+ };
281
289
 
282
290
  export type FindNextPickupDate = (params: {
283
291
  fecha?: string;
@@ -320,28 +328,29 @@ export type DataToInsert = {
320
328
  externals: InsertContentShipmentExternal[];
321
329
  };
322
330
 
323
- type InsertContentShipmentLine = {
324
- id_envio: number,
325
- bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
326
- }
331
+ export type InsertContentShipmentLine = {
332
+ id_envio: number;
333
+ bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
334
+ };
327
335
 
328
- type InsertContentShipmentData =
329
- UserDefaultConfigurationContent & { id_envio: number }
336
+ type InsertContentShipmentData = UserDefaultConfigurationContent & {
337
+ id_envio: number;
338
+ };
330
339
 
331
340
  type InsertContentShipmentDetail = {
332
- id_envio: number;
333
- bulto: Bulto['bulto'];
334
- }
341
+ id_envio: number;
342
+ bulto: Bulto['bulto'];
343
+ };
335
344
 
336
- type InsertContentShipmentExternal = {
337
- id_envio_temporal_usuario: number;
338
- codigo_envio_externo: string;
339
- id_usuario: number;
340
- fecha_hora_creacion: string;
341
- servicio: Type;
342
- id_interno_shopify?: string;
343
- fecha_creacion_externa: string | null;
344
- marketplaceId?: string | null;
345
- id_documento_holded?: string;
346
- tipo_documento_holded?: string;
347
- }
345
+ type InsertContentShipmentExternal = {
346
+ id_envio_temporal_usuario: number;
347
+ codigo_envio_externo: string;
348
+ id_usuario: number;
349
+ fecha_hora_creacion: string;
350
+ servicio: Type;
351
+ id_interno_shopify?: string;
352
+ fecha_creacion_externa: string | null;
353
+ marketplaceId?: string | null;
354
+ id_documento_holded?: string;
355
+ tipo_documento_holded?: string;
356
+ };