cardus 0.0.37 → 0.0.39

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;
@@ -117,7 +117,7 @@ class IntegrationManager {
117
117
  orders: allOrders,
118
118
  type: this.type
119
119
  });
120
- const isPriorityByDefault = () => __awaiter(this, void 0, void 0, function* () {
120
+ const checkIsPriorityByDefault = () => __awaiter(this, void 0, void 0, function* () {
121
121
  // TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
122
122
  const usuariosGeneiPriority = yield this.services.customizationService.getUsersWithSection(8);
123
123
  const esPotencialmentePriority = usuariosGeneiPriority.some((seccion) => seccion.id_usuario === user.id_usuario ||
@@ -130,6 +130,7 @@ class IntegrationManager {
130
130
  return +user.priority_defecto;
131
131
  }
132
132
  });
133
+ const isPriorityByDefault = yield checkIsPriorityByDefault();
133
134
  const insertOrdersResult = yield new this.executionManager({
134
135
  arrayParams: allOrders,
135
136
  executable: (order) => __awaiter(this, void 0, void 0, function* () {
@@ -142,13 +143,13 @@ class IntegrationManager {
142
143
  defaultAgencyId: agencyId,
143
144
  userId: idUsuario,
144
145
  integrationId: this.shipmentType,
145
- tempShipmentData: parsedOrder,
146
+ tempShipmentData: parsedOrder
146
147
  }),
147
148
  warehouseId,
148
149
  sellerAddress,
149
150
  idUsuario,
150
151
  group,
151
- isPriority: yield isPriorityByDefault(),
152
+ isPriority: isPriorityByDefault
152
153
  });
153
154
  }),
154
155
  regularExecutionTime: 8000, // ms
@@ -185,8 +186,9 @@ class IntegrationManager {
185
186
  });
186
187
  };
187
188
  let userConfiguration = null;
188
- const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
189
- if (userSavedData.length === 0) {
189
+ const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
190
+ [];
191
+ if (userSavedData.length > 0) {
190
192
  userConfiguration = userSavedData;
191
193
  }
192
194
  else {
@@ -194,7 +196,7 @@ class IntegrationManager {
194
196
  userConfiguration = userFakeData;
195
197
  }
196
198
  if (userConfiguration && userConfiguration !== null) {
197
- tempShimpmentIds.forEach(tempShimpmentId => {
199
+ tempShimpmentIds.forEach((tempShimpmentId) => {
198
200
  insert(userConfiguration, tempShimpmentId);
199
201
  });
200
202
  }
package/index.ts CHANGED
@@ -23,15 +23,15 @@ import {
23
23
  GetAgencyIdForTempShipment,
24
24
  IsPriority,
25
25
  CustomizationService,
26
- DataToInsert,
26
+ DataToInsert
27
27
  } from './types';
28
28
 
29
29
  const dataToInsert: DataToInsert = {
30
30
  lines: [],
31
31
  contents: [],
32
32
  details: [],
33
- externals: [],
34
- }
33
+ externals: []
34
+ };
35
35
 
36
36
  interface Services {
37
37
  integrationsService: IntegrationsService;
@@ -69,7 +69,7 @@ export class IntegrationManager {
69
69
  countriesService: params.countriesService,
70
70
  configurationService: params.configurationService,
71
71
  usersService: params.usersService,
72
- customizationService: params.customizationService,
72
+ customizationService: params.customizationService
73
73
  };
74
74
 
75
75
  this.shipmentType = params.shipmentType;
@@ -102,11 +102,12 @@ export class IntegrationManager {
102
102
  type: this.type
103
103
  });
104
104
 
105
- const isPriorityByDefault = async () => {
105
+ const checkIsPriorityByDefault = async () => {
106
106
  // TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
107
- const usuariosGeneiPriority = await this.services.customizationService.getUsersWithSection(8);
107
+ const usuariosGeneiPriority =
108
+ await this.services.customizationService.getUsersWithSection(8);
108
109
  const esPotencialmentePriority = usuariosGeneiPriority.some(
109
- (seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any; }) =>
110
+ (seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any }) =>
110
111
  seccion.id_usuario === user.id_usuario ||
111
112
  seccion.tipo_cliente === user.tipo_cliente ||
112
113
  seccion.id_comercial === user.id_comercial
@@ -119,6 +120,8 @@ export class IntegrationManager {
119
120
  }
120
121
  };
121
122
 
123
+ const isPriorityByDefault = await checkIsPriorityByDefault();
124
+
122
125
  const insertOrdersResult = await new this.executionManager({
123
126
  arrayParams: allOrders,
124
127
  executable: async (order: OriginalOrder) => {
@@ -132,13 +135,13 @@ export class IntegrationManager {
132
135
  defaultAgencyId: agencyId,
133
136
  userId: idUsuario,
134
137
  integrationId: this.shipmentType,
135
- tempShipmentData: parsedOrder,
138
+ tempShipmentData: parsedOrder
136
139
  }),
137
140
  warehouseId,
138
141
  sellerAddress,
139
142
  idUsuario,
140
143
  group,
141
- isPriority: await isPriorityByDefault(),
144
+ isPriority: isPriorityByDefault
142
145
  });
143
146
  },
144
147
  regularExecutionTime: 8000, // ms
@@ -163,10 +166,18 @@ export class IntegrationManager {
163
166
  (successfullShipment) => successfullShipment.idEnvioTemporal
164
167
  )
165
168
  });
166
- await integrationsService.insertTempShipmentMultipleLines(dataToInsert.lines);
167
- await integrationsService.insertTempShipmentMultipleDetails(dataToInsert.details);
168
- await integrationsService.insertTempShipmentMultipleContents(dataToInsert.contents);
169
- await integrationsService.insertTempShipmentMultipleExternals(dataToInsert.externals);
169
+ await integrationsService.insertTempShipmentMultipleLines(
170
+ dataToInsert.lines
171
+ );
172
+ await integrationsService.insertTempShipmentMultipleDetails(
173
+ dataToInsert.details
174
+ );
175
+ await integrationsService.insertTempShipmentMultipleContents(
176
+ dataToInsert.contents
177
+ );
178
+ await integrationsService.insertTempShipmentMultipleExternals(
179
+ dataToInsert.externals
180
+ );
170
181
 
171
182
  return { filteredOrders, insertedTempShipments: successfullShipments };
172
183
  }
@@ -175,34 +186,31 @@ export class IntegrationManager {
175
186
  user,
176
187
  tempShimpmentIds
177
188
  }: {
178
- user: { id_usuario: number, dni: string };
189
+ user: { id_usuario: number; dni: string };
179
190
  tempShimpmentIds: number[];
180
191
  }) {
181
- const idUsuario = user.id_usuario
182
- const { configurationService } =
183
- this.services;
192
+ const idUsuario = user.id_usuario;
193
+ const { configurationService } = this.services;
184
194
 
185
195
  const insert = (
186
196
  data: UserDefaultConfigurationContent[],
187
197
  tempShimpmentId: number
188
198
  ) => {
189
199
  data.forEach((tempContent) => {
190
- dataToInsert.contents.push({
191
- ...tempContent,
192
- id_envio: tempShimpmentId
193
- });
194
- })
200
+ dataToInsert.contents.push({
201
+ ...tempContent,
202
+ id_envio: tempShimpmentId
203
+ });
204
+ });
195
205
  };
196
206
 
197
207
  let userConfiguration: UserDefaultConfigurationContent[] | any = null;
198
208
  const userSavedData =
199
- (await configurationService.getDefaultProformaConfiguration(
200
- idUsuario
201
- )) || [];
202
- if (userSavedData.length === 0){
209
+ (await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
210
+ [];
211
+ if (userSavedData.length > 0) {
203
212
  userConfiguration = userSavedData;
204
- }
205
- else {
213
+ } else {
206
214
  const userFakeData =
207
215
  configurationService.getFakeDefaultProformaConfiguration(
208
216
  idUsuario,
@@ -210,10 +218,10 @@ export class IntegrationManager {
210
218
  );
211
219
  userConfiguration = userFakeData;
212
220
  }
213
- if (userConfiguration && userConfiguration !== null){
214
- tempShimpmentIds.forEach(tempShimpmentId => {
221
+ if (userConfiguration && userConfiguration !== null) {
222
+ tempShimpmentIds.forEach((tempShimpmentId) => {
215
223
  insert(userConfiguration, tempShimpmentId);
216
- })
224
+ });
217
225
  }
218
226
  }
219
227
 
@@ -232,7 +240,7 @@ export class IntegrationManager {
232
240
  sellerAddress: SellerAddress;
233
241
  idUsuario: number;
234
242
  group: Group;
235
- isPriority: IsPriority
243
+ isPriority: IsPriority;
236
244
  }): Promise<ModifiedOrderExtended> => {
237
245
  const idEnvioTemporal = await this.insertTempShipment({
238
246
  order,
@@ -240,7 +248,7 @@ export class IntegrationManager {
240
248
  warehouseId,
241
249
  sellerAddress,
242
250
  idUsuario,
243
- isPriority,
251
+ isPriority
244
252
  });
245
253
 
246
254
  if (!idEnvioTemporal)
@@ -270,7 +278,7 @@ export class IntegrationManager {
270
278
  warehouseId: number;
271
279
  sellerAddress: SellerAddress;
272
280
  idUsuario: number;
273
- isPriority: IsPriority
281
+ isPriority: IsPriority;
274
282
  }) => {
275
283
  const tempShipmentData = await cookTempShipment({
276
284
  order,
@@ -299,7 +307,6 @@ export class IntegrationManager {
299
307
  order: ModifiedOrder;
300
308
  idEnvioTemporal: number;
301
309
  }): undefined => {
302
-
303
310
  dataToInsert.externals.push({
304
311
  id_envio_temporal_usuario: idEnvioTemporal,
305
312
  codigo_envio_externo: order.codigoEnvioExterno,
@@ -313,7 +320,7 @@ export class IntegrationManager {
313
320
  marketplaceId: order.marketplaceId,
314
321
  id_documento_holded: order.idDocumentoHolded,
315
322
  tipo_documento_holded: order.tipoDocumentoHolded || ''
316
- })
323
+ });
317
324
  };
318
325
 
319
326
  insertTempShipmentLines = async ({
@@ -334,7 +341,7 @@ export class IntegrationManager {
334
341
  ancho: group.width,
335
342
  largo: group.length
336
343
  }
337
- })
344
+ });
338
345
  }
339
346
  };
340
347
 
@@ -349,7 +356,6 @@ export class IntegrationManager {
349
356
  crearBulto: CrearBulto;
350
357
  estaAgrupado: boolean;
351
358
  }) {
352
-
353
359
  const obtenerBultosYCantidades = orders.map(
354
360
  async ({ idEnvioTemporal, lineas }) => {
355
361
  if (!idEnvioTemporal) return null;
@@ -394,10 +400,9 @@ export class IntegrationManager {
394
400
  bulto
395
401
  });
396
402
  });
397
-
398
403
  } catch (e) {
399
404
  console.log(e);
400
405
  }
401
406
  });
402
407
  }
403
- }
408
+ }
@@ -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.37",
3
+ "version": "0.0.39",
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
@@ -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;
@@ -321,27 +329,28 @@ export type DataToInsert = {
321
329
  };
322
330
 
323
331
  type InsertContentShipmentLine = {
324
- id_envio: number,
325
- bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
326
- }
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
+ };