cardus 0.0.71 → 0.0.73

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
@@ -91,6 +91,7 @@ class IntegrationManager {
91
91
  const sellerAddress = warehouseId > 0
92
92
  ? yield addressesService.getWarehouseAddress(idUsuario)
93
93
  : yield addressesService.getAddress(addressId, idUsuario);
94
+ const country = yield this.services.countriesService.getCountry(sellerAddress.id_pais);
94
95
  const allOrders = yield fetchAllOrders();
95
96
  const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
96
97
  id_usuario: idUsuario,
@@ -149,7 +150,8 @@ class IntegrationManager {
149
150
  });
150
151
  yield this.insertUserDefaultConfigurationContent({
151
152
  user,
152
- tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
153
+ tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal),
154
+ countryName: country.nombre_pais_en
153
155
  });
154
156
  // modificamos la agencia, cuando se tenga que hacer
155
157
  yield Promise.allSettled(successfullShipments.map((order) => __awaiter(this, void 0, void 0, function* () {
@@ -174,7 +176,7 @@ class IntegrationManager {
174
176
  })));
175
177
  yield Promise.allSettled([
176
178
  integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines),
177
- integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details.map((detail) => (Object.assign(Object.assign({}, detail), { url_producto: JSON.stringify(this.dataToInsert.details), ski_producto: 'AAAAA' })))),
179
+ integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details),
178
180
  integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents),
179
181
  integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals)
180
182
  ]);
@@ -186,12 +188,14 @@ class IntegrationManager {
186
188
  });
187
189
  }
188
190
  insertUserDefaultConfigurationContent(_a) {
189
- return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
191
+ return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds, countryName }) {
190
192
  const idUsuario = user.id_usuario;
191
193
  const { configurationService, llmAPIService } = this.services;
192
194
  const insert = (data, tempShimpmentId) => {
193
195
  data.forEach((tempContent) => {
194
- this.dataToInsert.contents.push(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
196
+ if (tempContent.contenido) {
197
+ this.dataToInsert.contents.push(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
198
+ }
195
199
  });
196
200
  };
197
201
  // Limpia los contenidos para eliminar valores no deseados
@@ -208,10 +212,13 @@ class IntegrationManager {
208
212
  [];
209
213
  if (integrationShipmentDetails) {
210
214
  const shipmentContentFromDetails = yield Promise.all(integrationShipmentDetails.map((detail) => __awaiter(this, void 0, void 0, function* () {
211
- const taric = yield llmAPIService.getTaricCode('chatgpt', detail.bulto.nombre_producto || '');
215
+ const taric = detail.bulto.nombre_producto
216
+ ? yield llmAPIService.getTaricCode('chatgpt', detail.bulto.nombre_producto)
217
+ : null;
212
218
  return {
219
+ id_envio: detail.id_envio,
213
220
  id_usuario: idUsuario,
214
- contenido: JSON.stringify(this.dataToInsert.details),
221
+ contenido: detail.bulto.nombre_producto,
215
222
  valor: detail.bulto.valor || getRandomContentValue(),
216
223
  dni: user.dni,
217
224
  taric,
@@ -219,7 +226,7 @@ class IntegrationManager {
219
226
  eori_exportacion: user.eori_export,
220
227
  peso_bruto: detail.bulto.peso,
221
228
  peso_neto: detail.bulto.peso,
222
- origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
229
+ origen: countryName,
223
230
  cantidad: detail.cantidad,
224
231
  reason_export: '1'
225
232
  };
package/index.ts CHANGED
@@ -111,6 +111,9 @@ export class IntegrationManager {
111
111
  warehouseId > 0
112
112
  ? await addressesService.getWarehouseAddress(idUsuario)
113
113
  : await addressesService.getAddress(addressId, idUsuario);
114
+ const country = await this.services.countriesService.getCountry(
115
+ sellerAddress.id_pais
116
+ );
114
117
 
115
118
  const allOrders = await fetchAllOrders();
116
119
  const filteredOrders =
@@ -194,7 +197,8 @@ export class IntegrationManager {
194
197
  user,
195
198
  tempShimpmentIds: successfullShipments.map(
196
199
  (successfullShipment) => successfullShipment.idEnvioTemporal
197
- )
200
+ ),
201
+ countryName: country.nombre_pais_en
198
202
  });
199
203
 
200
204
  // modificamos la agencia, cuando se tenga que hacer
@@ -230,11 +234,7 @@ export class IntegrationManager {
230
234
  this.dataToInsert.lines
231
235
  ),
232
236
  integrationsService.insertTempShipmentMultipleDetails(
233
- this.dataToInsert.details.map((detail) => ({
234
- ...detail,
235
- url_producto: JSON.stringify(this.dataToInsert.details),
236
- ski_producto: 'AAAAA'
237
- }))
237
+ this.dataToInsert.details
238
238
  ),
239
239
  integrationsService.insertTempShipmentMultipleContents(
240
240
  this.dataToInsert.contents
@@ -253,10 +253,12 @@ export class IntegrationManager {
253
253
 
254
254
  async insertUserDefaultConfigurationContent({
255
255
  user,
256
- tempShimpmentIds
256
+ tempShimpmentIds,
257
+ countryName
257
258
  }: {
258
259
  user: Record<string, string | number>;
259
260
  tempShimpmentIds: number[];
261
+ countryName: string;
260
262
  }) {
261
263
  const idUsuario = user.id_usuario as number;
262
264
  const { configurationService, llmAPIService } = this.services;
@@ -266,10 +268,12 @@ export class IntegrationManager {
266
268
  tempShimpmentId: number
267
269
  ) => {
268
270
  data.forEach((tempContent) => {
269
- this.dataToInsert.contents.push({
270
- ...tempContent,
271
- id_envio: tempShimpmentId
272
- });
271
+ if (tempContent.contenido) {
272
+ this.dataToInsert.contents.push({
273
+ ...tempContent,
274
+ id_envio: tempShimpmentId
275
+ });
276
+ }
273
277
  });
274
278
  };
275
279
 
@@ -298,14 +302,17 @@ export class IntegrationManager {
298
302
  if (integrationShipmentDetails) {
299
303
  const shipmentContentFromDetails = await Promise.all(
300
304
  integrationShipmentDetails.map(async (detail) => {
301
- const taric = await llmAPIService.getTaricCode(
302
- 'chatgpt',
303
- detail.bulto.nombre_producto || ''
304
- );
305
+ const taric = detail.bulto.nombre_producto
306
+ ? await llmAPIService.getTaricCode(
307
+ 'chatgpt',
308
+ detail.bulto.nombre_producto
309
+ )
310
+ : null;
305
311
 
306
312
  return {
313
+ id_envio: detail.id_envio,
307
314
  id_usuario: idUsuario,
308
- contenido: JSON.stringify(this.dataToInsert.details),
315
+ contenido: detail.bulto.nombre_producto,
309
316
  valor: detail.bulto.valor || getRandomContentValue(),
310
317
  dni: user.dni,
311
318
  taric,
@@ -313,7 +320,7 @@ export class IntegrationManager {
313
320
  eori_exportacion: user.eori_export,
314
321
  peso_bruto: detail.bulto.peso,
315
322
  peso_neto: detail.bulto.peso,
316
- origen: 1, // Sacar del país de origen de la orden pendiente. Nombre de país en inglés.
323
+ origen: countryName,
317
324
  cantidad: detail.cantidad,
318
325
  reason_export: '1'
319
326
  } as UserDefaultConfigurationContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -266,11 +266,17 @@ export type AddressesService = {
266
266
  getAddress: (addressId: number, idUsuario: number) => Promise<SellerAddress>;
267
267
  };
268
268
 
269
- type Country = { nombre_pais: string; id_pais?: number };
269
+ type Country = {
270
+ nombre_pais: string;
271
+ id_pais?: number;
272
+ nombre_pais_en: string;
273
+ };
270
274
  type Provincia = { nombre_provincia?: string };
271
275
  type Zone = string;
272
276
 
273
277
  export type CountriesService = {
278
+ getCountry: (id_pais: Country['id_pais']) => Promise<Country>;
279
+
274
280
  getCountryFromCountryCode: (
275
281
  countryCode: string
276
282
  ) => Promise<{ nombre_pais: string; id_pais?: number }>;
@@ -289,6 +295,7 @@ export type CountriesService = {
289
295
  };
290
296
 
291
297
  export type UserDefaultConfigurationContent = {
298
+ id_envio: number;
292
299
  id_usuario: number;
293
300
  contenido: string;
294
301
  valor: number;
@@ -298,7 +305,7 @@ export type UserDefaultConfigurationContent = {
298
305
  eori_exportacion: string;
299
306
  peso_bruto: number;
300
307
  peso_neto: number;
301
- origen: number;
308
+ origen: string;
302
309
  cantidad: number;
303
310
  reason_export: '1' | '2' | '3' | '4' | '5';
304
311
  };