cardus 0.0.19 → 0.0.20

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
@@ -57,7 +57,8 @@ class IntegrationManager {
57
57
  id_usuario: idUsuario,
58
58
  fecha_hora_creacion: (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss'),
59
59
  servicio: this.type,
60
- id_interno_shopify: order.idInternoShopify
60
+ id_interno_shopify: order.idInternoShopify,
61
+ fecha_creacion_externa: (0, moment_1.default)(order === null || order === void 0 ? void 0 : order.fecha_creacion_externa).isValid() ? (0, moment_1.default)(order.fecha_creacion_externa).format("YYYY-MM-DD HH:mm:ss") : null
61
62
  });
62
63
  return idEnvioExterno;
63
64
  });
package/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import moment from 'moment';
2
+
2
3
  import { cookTempShipment } from './insertTempShipment';
4
+
3
5
  import {
4
6
  ModifiedOrderExtended,
5
7
  CrearBulto,
@@ -53,6 +55,7 @@ export class IntegrationManager {
53
55
  configurationService: params.configurationService,
54
56
  usersService: params.usersService
55
57
  };
58
+
56
59
  this.shipmentType = params.shipmentType;
57
60
  this.type = params.type;
58
61
  this.executionManager = params.executionManager;
@@ -74,7 +77,6 @@ export class IntegrationManager {
74
77
  : await addressesService.getAddress(addressId, idUsuario);
75
78
 
76
79
  const allOrders = await fetchAllOrders();
77
-
78
80
  const filteredOrders =
79
81
  await integrationsService.filterExternalDuplicatedOrders({
80
82
  idUsuario,
@@ -88,6 +90,7 @@ export class IntegrationManager {
88
90
  const parsedOrder = await modificarOrdenOriginal({
89
91
  originalOrder: order
90
92
  });
93
+
91
94
  const duplicatedTempShipment =
92
95
  await integrationsService.checkDuplicateTempShipment(
93
96
  parsedOrder.codigoEnvioExterno,
@@ -139,6 +142,7 @@ export class IntegrationManager {
139
142
  }) {
140
143
  const { usersService, configurationService, integrationsService } =
141
144
  this.services;
145
+
142
146
  const insert = async (
143
147
  data: UserDefaultConfigurationContent[],
144
148
  tempShimpmentId: number
@@ -147,13 +151,16 @@ export class IntegrationManager {
147
151
  data.map(async (tempContent) => {
148
152
  await integrationsService.insertTempContent({
149
153
  ...tempContent,
154
+
150
155
  id_envio: tempShimpmentId
151
156
  });
152
157
  })
153
158
  );
154
159
  };
160
+
155
161
  const insertOrdersResult = await new this.executionManager({
156
162
  arrayParams: tempShimpmentIds,
163
+
157
164
  executable: async (order: any) => {
158
165
  const userSavedData =
159
166
  (await configurationService.getDefaultProformaConfiguration(
@@ -169,7 +176,6 @@ export class IntegrationManager {
169
176
  idUsuario,
170
177
  user.dni
171
178
  );
172
-
173
179
  await insert(userFakeData, order);
174
180
  }
175
181
  },
@@ -211,9 +217,7 @@ export class IntegrationManager {
211
217
  });
212
218
 
213
219
  const grouped = Number(group?.grouped === 1);
214
-
215
220
  if (grouped) await this.insertTempShipmentLines({ idEnvioTemporal, group });
216
-
217
221
  return Object.assign(order, { idEnvioTemporal });
218
222
  };
219
223
 
@@ -240,6 +244,7 @@ export class IntegrationManager {
240
244
  findNextPickupDate: this.findNextPickupDate,
241
245
  countriesService: this.services.countriesService
242
246
  });
247
+
243
248
  return await this.services.integrationsService.insertTempShipment(
244
249
  tempShipmentData
245
250
  );
@@ -261,7 +266,8 @@ export class IntegrationManager {
261
266
  id_usuario: idUsuario,
262
267
  fecha_hora_creacion: moment().format('YYYY-MM-DD HH:mm:ss'),
263
268
  servicio: this.type,
264
- id_interno_shopify: order.idInternoShopify
269
+ id_interno_shopify: order.idInternoShopify,
270
+ fecha_creacion_externa: moment(order?.fecha_creacion_externa).isValid() ? moment(order.fecha_creacion_externa).format("YYYY-MM-DD HH:mm:ss") : null
265
271
  });
266
272
 
267
273
  return idEnvioExterno;
@@ -275,6 +281,7 @@ export class IntegrationManager {
275
281
  group: Group;
276
282
  }) => {
277
283
  const grouped = group.grouped === 1 || group.grouped === '1';
284
+
278
285
  if (grouped)
279
286
  await this.services.integrationsService.insertTempShipmentLines({
280
287
  id_envio: idEnvioTemporal,
@@ -310,9 +317,7 @@ export class IntegrationManager {
310
317
  lineItems: { idEnvioTemporal, line },
311
318
  idUsuario
312
319
  });
313
-
314
320
  if (cantidad === 0) return null;
315
-
316
321
  return { bulto, cantidad, idEnvioTemporal };
317
322
  })
318
323
  );
@@ -323,20 +328,24 @@ export class IntegrationManager {
323
328
  const bultosYCantidadesAnidados = await Promise.all(
324
329
  obtenerBultosYCantidades
325
330
  );
331
+
326
332
  const bultosYCantidades = bultosYCantidadesAnidados
327
333
  .flat()
328
334
  .filter(Boolean);
335
+
329
336
  res(bultosYCantidades);
330
337
  })) as Array<any>;
331
338
 
332
339
  bultosYCantidades.forEach(({ bulto, cantidad, idEnvioTemporal }) => {
333
340
  try {
334
341
  const arrayFake = Array.from({ length: Number(cantidad) });
342
+
335
343
  arrayFake.forEach(() => {
336
344
  if (!estaAgrupado) {
337
345
  quantityRelatedFunctions.push(
338
346
  integrationsService.insertTempShipmentLines({
339
347
  id_envio: idEnvioTemporal,
348
+
340
349
  bulto
341
350
  })
342
351
  );
@@ -30,7 +30,6 @@ export const cookTempShipment = async ({
30
30
  countriesService: CountriesService;
31
31
  }): Promise<Shipment> => {
32
32
  let zonaLLegada = {};
33
-
34
33
  if (order.codigoPaisLLegada)
35
34
  zonaLLegada = await countriesService.getCountryFromCountryCode(
36
35
  order.codigoPaisLLegada
@@ -52,6 +51,7 @@ export const cookTempShipment = async ({
52
51
  mail_salida: sellerAddress.mail
53
52
  });
54
53
 
54
+
55
55
  const setUbicacionComprador = async (order: ModifiedOrder) => {
56
56
  type CompradorLocation = {
57
57
  pais_llegada: string | null;
@@ -59,11 +59,13 @@ export const cookTempShipment = async ({
59
59
  id_zona_llegada: string | null;
60
60
  };
61
61
 
62
+
62
63
  const compradorLocation: CompradorLocation = {
63
64
  pais_llegada: null,
64
65
  provincia_llegada: null,
65
66
  id_zona_llegada: null
66
67
  };
68
+
67
69
  if (order.codigoPaisLLegada) {
68
70
  const _zonaLLegada = zonaLLegada as ZonaLLegada;
69
71
  compradorLocation.pais_llegada = _zonaLLegada?.nombre_pais || null;
@@ -88,26 +90,32 @@ export const cookTempShipment = async ({
88
90
  return compradorLocation;
89
91
  };
90
92
 
93
+
91
94
  const setDatosComprador = async (order: ModifiedOrder) => ({
92
95
  nom_ape_llegada: order.primerApellidoLLegada
93
96
  ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
94
97
  : order.nombreLLegada,
98
+
95
99
  contacto_llegada: order.primerApellidoLLegada
96
100
  ? order.nombreLLegada + ' ' + order.primerApellidoLLegada
97
101
  : order.nombreLLegada,
102
+
98
103
  direccion_llegada: order.direccionLLegada2
99
104
  ? order.direccionLLegada1 + ' ' + order.direccionLLegada2
100
105
  : order.direccionLLegada1,
106
+
101
107
  cod_pos_llegada: order.codigoPostalLLegada,
102
108
  poblacion_llegada: order.ciudadLLegada,
103
109
  tlf_llegada: order.telefonoLLegada || 'no informado',
104
110
  mail_llegada: order.emailLLegada || 'no informado'
105
111
  });
106
112
 
113
+
107
114
  const setReembolso = (order: ModifiedOrder) => {
108
115
  return { cantidad_contrareembolso: order.cantidadContrareembolso };
109
116
  };
110
117
 
118
+
111
119
  const setFechas = async (order: ModifiedOrder) => {
112
120
  const date = moment().format('YYYY-MM-DD');
113
121
  const beginHour = '09:00';
@@ -162,11 +170,13 @@ export const cookTempShipment = async ({
162
170
  ...order,
163
171
  ...accumulated
164
172
  });
173
+
165
174
  return {
166
175
  ...accumulated,
167
176
  ...stepResult
168
177
  };
178
+
169
179
  }, {})) as Shipment;
170
180
 
171
181
  return dataInsert;
172
- };
182
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,4 +28,4 @@
28
28
  "dependencies": {
29
29
  "moment": "^2.30.1"
30
30
  }
31
- }
31
+ }
package/types/index.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export type AnyObject = Record<string, any>; // Object with whichever properties
2
-
3
2
  export type OriginalOrder = AnyObject;
4
-
5
3
  export type Shipment = {
6
4
  id_usuario: number;
7
5
  id_agencia: number;
@@ -62,7 +60,6 @@ const shipmentTypes = {
62
60
  };
63
61
 
64
62
  export type ShipmentType = (typeof shipmentTypes)[keyof typeof shipmentTypes];
65
-
66
63
  export type Bulto = {
67
64
  id_envio: number;
68
65
  bulto: {
@@ -93,6 +90,7 @@ export type ModifiedOrder = {
93
90
  codigoEnvioExterno: string;
94
91
  idInternoShopify?: string;
95
92
  precio: number | null;
93
+ fecha_creacion_externa?: string | null;
96
94
  };
97
95
 
98
96
  export interface ModifiedOrderExtended extends ModifiedOrder {
@@ -100,10 +98,13 @@ export interface ModifiedOrderExtended extends ModifiedOrder {
100
98
  }
101
99
 
102
100
  type FetchAllOrders = () => Promise<OriginalOrder[]>;
101
+
103
102
  export type CrearBulto = (params: {
104
103
  lineItems: { idEnvioTemporal: number; line: AnyObject };
104
+
105
105
  idUsuario: number;
106
106
  }) => Promise<Bulto>;
107
+
107
108
  type ModificarOrdenOriginal = (param: {
108
109
  originalOrder: OriginalOrder;
109
110
  }) => Promise<ModifiedOrder>;
@@ -141,11 +142,14 @@ export type IntegrationsService = {
141
142
  orders: OriginalOrder[];
142
143
  type: Type;
143
144
  }) => Promise<OriginalOrder[]>;
145
+
144
146
  checkDuplicateTempShipment: (
145
147
  codigoEnvioExterno: string,
146
148
  idUsuario: number
147
149
  ) => Promise<boolean>;
150
+
148
151
  insertTempShipment: (params: Shipment) => number | false;
152
+
149
153
  insertExternalShipment: (params: {
150
154
  id_envio_temporal_usuario: number;
151
155
  codigo_envio_externo: string;
@@ -153,15 +157,19 @@ export type IntegrationsService = {
153
157
  fecha_hora_creacion: string;
154
158
  servicio: Type;
155
159
  id_interno_shopify?: string;
160
+ fecha_creacion_externa: string | null
156
161
  }) => number | false;
162
+
157
163
  insertTempShipmentLines: (params: {
158
164
  id_envio: number;
159
165
  bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
160
166
  }) => Promise<undefined>;
167
+
161
168
  insertTempDetailsShipment: (params: {
162
169
  id_envio: number;
163
170
  bulto: Bulto['bulto'];
164
171
  }) => Promise<undefined>;
172
+
165
173
  insertTempContent: (
166
174
  params: UserDefaultConfigurationContent & { id_envio: number }
167
175
  ) => Promise<number | false>;
@@ -184,6 +192,7 @@ export type SellerAddress = {
184
192
 
185
193
  export type AddressesService = {
186
194
  getWarehouseAddress: (idUsuario: number) => Promise<SellerAddress>;
195
+
187
196
  getAddress: (addressId: number, idUsuario: number) => Promise<SellerAddress>;
188
197
  };
189
198
 
@@ -195,12 +204,16 @@ export type CountriesService = {
195
204
  getCountryFromCountryCode: (
196
205
  countryCode: string
197
206
  ) => Promise<{ nombre_pais: string; id_pais?: number }>;
207
+
198
208
  getProvinceByCountryIdAndPostalCode: (
199
209
  id_pais: Country['id_pais'],
210
+
200
211
  zipCode: string
201
212
  ) => Promise<Provincia>;
213
+
202
214
  getZoneIdByCountryIdAndPostalCode: (
203
215
  id_pais: Country['id_pais'],
216
+
204
217
  zipCode: string
205
218
  ) => Promise<Zone>;
206
219
  };
@@ -228,8 +241,10 @@ export type ConfigurationService = {
228
241
  getDefaultProformaConfiguration: (
229
242
  id_usuario: number
230
243
  ) => Promise<UserDefaultConfigurationContent[] | false>;
244
+
231
245
  getFakeDefaultProformaConfiguration: (
232
246
  id_usuario: number,
247
+
233
248
  dni: string
234
249
  ) => UserDefaultConfigurationContent[];
235
250
  };
@@ -262,5 +277,5 @@ type ExecutionManagerUploadReturn = {
262
277
 
263
278
  export type ExecutionManager = {
264
279
  upload(): ExecutionManagerUploadReturn[];
265
- new (params: ExecutionManagerConstructorParams): ExecutionManager;
280
+ new(params: ExecutionManagerConstructorParams): ExecutionManager;
266
281
  };