cardus 0.0.108 → 0.0.112
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/__tests__/insertTempShipments.test.ts +1 -1
- package/dist/__tests__/insertTempShipments.test.js +1 -1
- package/dist/index.js +18 -21
- package/index.ts +33 -31
- package/package.json +1 -1
- package/types/index.ts +3 -3
|
@@ -376,7 +376,7 @@ describe('IntegrationManager.insertTempShipments', () => {
|
|
|
376
376
|
expect(addressesService.getAddress).not.toHaveBeenCalledWith(10, 77);
|
|
377
377
|
});
|
|
378
378
|
|
|
379
|
-
it('uses sellerAddress from the order when addressId is not provided', async () => {
|
|
379
|
+
it('uses sellerAddress from the order when addressId is not provided ', async () => {
|
|
380
380
|
const { manager, addressesService, integrationsService } = buildFixture();
|
|
381
381
|
arrangeDefaultStubs({ manager, shipmentId: 12345 });
|
|
382
382
|
|
|
@@ -316,7 +316,7 @@ describe('IntegrationManager.insertTempShipments', () => {
|
|
|
316
316
|
expect(addressesService.getWarehouseAddress).toHaveBeenCalledWith(77);
|
|
317
317
|
expect(addressesService.getAddress).not.toHaveBeenCalledWith(10, 77);
|
|
318
318
|
}));
|
|
319
|
-
it('uses sellerAddress from the order when addressId is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
319
|
+
it('uses sellerAddress from the order when addressId is not provided ', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
320
320
|
const { manager, addressesService, integrationsService } = buildFixture();
|
|
321
321
|
arrangeDefaultStubs({ manager, shipmentId: 12345 });
|
|
322
322
|
yield manager.insertTempShipments({
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,6 @@ class IntegrationManager {
|
|
|
66
66
|
: addressId
|
|
67
67
|
? yield addressesService.getAddress(addressId, idUsuario)
|
|
68
68
|
: null;
|
|
69
|
-
let sellerAddressForContents = defaultSellerAddress;
|
|
70
69
|
const userIntegrationConfiguration = yield integrationsService.getDefaultIntegrationsData({
|
|
71
70
|
id_usuario: idUsuario,
|
|
72
71
|
id_integracion: this.integrationType
|
|
@@ -103,11 +102,10 @@ class IntegrationManager {
|
|
|
103
102
|
if (parsedOrder.direccionSalidaId) {
|
|
104
103
|
direccionSalida = yield addressesService.getAddress(parsedOrder.direccionSalidaId, idUsuario);
|
|
105
104
|
}
|
|
106
|
-
const currentSellerAddress = (_b = direccionSalida !== null && direccionSalida !== void 0 ? direccionSalida : parsedOrder.
|
|
105
|
+
const currentSellerAddress = (_b = direccionSalida !== null && direccionSalida !== void 0 ? direccionSalida : parsedOrder.direccionSalidaPersonalizada) !== null && _b !== void 0 ? _b : defaultSellerAddress;
|
|
107
106
|
if (!currentSellerAddress) {
|
|
108
107
|
throw new Error('Seller address could not be resolved');
|
|
109
108
|
}
|
|
110
|
-
sellerAddressForContents !== null && sellerAddressForContents !== void 0 ? sellerAddressForContents : (sellerAddressForContents = currentSellerAddress);
|
|
111
109
|
const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
|
|
112
110
|
order: parsedOrder,
|
|
113
111
|
shipmentType: this.shipmentType,
|
|
@@ -193,20 +191,18 @@ class IntegrationManager {
|
|
|
193
191
|
});
|
|
194
192
|
// details
|
|
195
193
|
this.dataToInsert.details.push(...shipmentDetails);
|
|
194
|
+
const country = yield this.services.countriesService.getCountry(currentSellerAddress.id_pais);
|
|
195
|
+
// mete los contents
|
|
196
|
+
yield this.insertUserDefaultConfigurationContent({
|
|
197
|
+
user,
|
|
198
|
+
countryName: country.nombre_pais_en,
|
|
199
|
+
shipmentDetails
|
|
200
|
+
});
|
|
196
201
|
return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
|
|
197
202
|
}),
|
|
198
203
|
regularExecutionTime: 8000, // ms
|
|
199
204
|
initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
|
|
200
205
|
}).upload();
|
|
201
|
-
if (!sellerAddressForContents) {
|
|
202
|
-
throw new Error('Seller address could not be resolved');
|
|
203
|
-
}
|
|
204
|
-
const country = yield this.services.countriesService.getCountry(sellerAddressForContents.id_pais);
|
|
205
|
-
// content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
|
|
206
|
-
yield this.insertUserDefaultConfigurationContent({
|
|
207
|
-
user,
|
|
208
|
-
countryName: country.nombre_pais_en
|
|
209
|
-
});
|
|
210
206
|
const arrayPackages = [...this.dataToInsert.lines.values()].flat().flat();
|
|
211
207
|
yield Promise.allSettled([
|
|
212
208
|
integrationsService.insertTempShipmentMultipleLines(arrayPackages),
|
|
@@ -227,7 +223,7 @@ class IntegrationManager {
|
|
|
227
223
|
});
|
|
228
224
|
}
|
|
229
225
|
insertUserDefaultConfigurationContent(_a) {
|
|
230
|
-
return __awaiter(this, arguments, void 0, function* ({ user, countryName }) {
|
|
226
|
+
return __awaiter(this, arguments, void 0, function* ({ user, countryName, shipmentDetails }) {
|
|
231
227
|
const idUsuario = user.id_usuario;
|
|
232
228
|
const { configurationService, llmAPIService } = this.services;
|
|
233
229
|
const insert = (data) => {
|
|
@@ -245,10 +241,8 @@ class IntegrationManager {
|
|
|
245
241
|
const getRandomContentValue = () => {
|
|
246
242
|
return Math.floor(Math.random() * 5) + 1;
|
|
247
243
|
};
|
|
248
|
-
const integrationShipmentDetails =
|
|
244
|
+
const integrationShipmentDetails = shipmentDetails;
|
|
249
245
|
let shipmentContent = null;
|
|
250
|
-
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
|
|
251
|
-
[];
|
|
252
246
|
if (integrationShipmentDetails) {
|
|
253
247
|
const shipmentContentFromDetails = yield Promise.all(integrationShipmentDetails.map((detail) => __awaiter(this, void 0, void 0, function* () {
|
|
254
248
|
let taric = null;
|
|
@@ -281,12 +275,15 @@ class IntegrationManager {
|
|
|
281
275
|
})));
|
|
282
276
|
shipmentContent = shipmentContentFromDetails;
|
|
283
277
|
}
|
|
284
|
-
else if (userSavedData.length > 0) {
|
|
285
|
-
shipmentContent = userSavedData;
|
|
286
|
-
}
|
|
287
278
|
else {
|
|
288
|
-
const
|
|
289
|
-
|
|
279
|
+
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
|
|
280
|
+
if (userSavedData.length > 0) {
|
|
281
|
+
shipmentContent = userSavedData;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
|
|
285
|
+
shipmentContent = userFakeData;
|
|
286
|
+
}
|
|
290
287
|
}
|
|
291
288
|
if (shipmentContent) {
|
|
292
289
|
shipmentContent = cleanContentData(shipmentContent);
|
package/index.ts
CHANGED
|
@@ -117,7 +117,6 @@ export class IntegrationManager {
|
|
|
117
117
|
: addressId
|
|
118
118
|
? await addressesService.getAddress(addressId, idUsuario)
|
|
119
119
|
: null;
|
|
120
|
-
let sellerAddressForContents = defaultSellerAddress;
|
|
121
120
|
|
|
122
121
|
const userIntegrationConfiguration =
|
|
123
122
|
await integrationsService.getDefaultIntegrationsData({
|
|
@@ -175,14 +174,14 @@ export class IntegrationManager {
|
|
|
175
174
|
);
|
|
176
175
|
}
|
|
177
176
|
const currentSellerAddress =
|
|
178
|
-
direccionSalida ??
|
|
177
|
+
direccionSalida ??
|
|
178
|
+
parsedOrder.direccionSalidaPersonalizada ??
|
|
179
|
+
defaultSellerAddress;
|
|
179
180
|
|
|
180
181
|
if (!currentSellerAddress) {
|
|
181
182
|
throw new Error('Seller address could not be resolved');
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
sellerAddressForContents ??= currentSellerAddress;
|
|
185
|
-
|
|
186
185
|
const tempShipmentData = await cookTempShipment({
|
|
187
186
|
order: parsedOrder,
|
|
188
187
|
shipmentType: this.shipmentType,
|
|
@@ -307,26 +306,23 @@ export class IntegrationManager {
|
|
|
307
306
|
// details
|
|
308
307
|
this.dataToInsert.details.push(...shipmentDetails);
|
|
309
308
|
|
|
309
|
+
const country = await this.services.countriesService.getCountry(
|
|
310
|
+
currentSellerAddress.id_pais
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
// mete los contents
|
|
314
|
+
await this.insertUserDefaultConfigurationContent({
|
|
315
|
+
user,
|
|
316
|
+
countryName: country.nombre_pais_en,
|
|
317
|
+
shipmentDetails
|
|
318
|
+
});
|
|
319
|
+
|
|
310
320
|
return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
|
|
311
321
|
},
|
|
312
322
|
regularExecutionTime: 8000, // ms
|
|
313
323
|
initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
|
|
314
324
|
}).upload();
|
|
315
325
|
|
|
316
|
-
if (!sellerAddressForContents) {
|
|
317
|
-
throw new Error('Seller address could not be resolved');
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const country = await this.services.countriesService.getCountry(
|
|
321
|
-
sellerAddressForContents.id_pais
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
// content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
|
|
325
|
-
await this.insertUserDefaultConfigurationContent({
|
|
326
|
-
user,
|
|
327
|
-
countryName: country.nombre_pais_en
|
|
328
|
-
});
|
|
329
|
-
|
|
330
326
|
const arrayPackages = [...this.dataToInsert.lines.values()].flat().flat();
|
|
331
327
|
|
|
332
328
|
await Promise.allSettled([
|
|
@@ -362,10 +358,12 @@ export class IntegrationManager {
|
|
|
362
358
|
|
|
363
359
|
async insertUserDefaultConfigurationContent({
|
|
364
360
|
user,
|
|
365
|
-
countryName
|
|
361
|
+
countryName,
|
|
362
|
+
shipmentDetails
|
|
366
363
|
}: {
|
|
367
364
|
user: Record<string, string | number>;
|
|
368
365
|
countryName: string;
|
|
366
|
+
shipmentDetails: InsertContentShipmentDetail[];
|
|
369
367
|
}) {
|
|
370
368
|
const idUsuario = user.id_usuario as number;
|
|
371
369
|
const { configurationService, llmAPIService } = this.services;
|
|
@@ -396,11 +394,8 @@ export class IntegrationManager {
|
|
|
396
394
|
return Math.floor(Math.random() * 5) + 1;
|
|
397
395
|
};
|
|
398
396
|
|
|
399
|
-
const integrationShipmentDetails =
|
|
397
|
+
const integrationShipmentDetails = shipmentDetails;
|
|
400
398
|
let shipmentContent: UserDefaultConfigurationContent[] | null = null;
|
|
401
|
-
const userSavedData =
|
|
402
|
-
(await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
|
|
403
|
-
[];
|
|
404
399
|
|
|
405
400
|
if (integrationShipmentDetails) {
|
|
406
401
|
const shipmentContentFromDetails = await Promise.all(
|
|
@@ -438,15 +433,22 @@ export class IntegrationManager {
|
|
|
438
433
|
);
|
|
439
434
|
|
|
440
435
|
shipmentContent = shipmentContentFromDetails;
|
|
441
|
-
} else if (userSavedData.length > 0) {
|
|
442
|
-
shipmentContent = userSavedData;
|
|
443
436
|
} else {
|
|
444
|
-
const
|
|
445
|
-
configurationService.
|
|
446
|
-
idUsuario
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
437
|
+
const userSavedData =
|
|
438
|
+
(await configurationService.getDefaultProformaConfiguration(
|
|
439
|
+
idUsuario
|
|
440
|
+
)) || [];
|
|
441
|
+
|
|
442
|
+
if (userSavedData.length > 0) {
|
|
443
|
+
shipmentContent = userSavedData;
|
|
444
|
+
} else {
|
|
445
|
+
const userFakeData =
|
|
446
|
+
configurationService.getFakeDefaultProformaConfiguration(
|
|
447
|
+
idUsuario,
|
|
448
|
+
user.dni as string
|
|
449
|
+
);
|
|
450
|
+
shipmentContent = userFakeData;
|
|
451
|
+
}
|
|
450
452
|
}
|
|
451
453
|
|
|
452
454
|
if (shipmentContent) {
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -123,7 +123,7 @@ export type ModifiedOrder = {
|
|
|
123
123
|
telefonoLLegada: string | undefined;
|
|
124
124
|
emailLLegada: string | undefined;
|
|
125
125
|
cantidadContrareembolso: number | null;
|
|
126
|
-
codigoEnvioExterno
|
|
126
|
+
codigoEnvioExterno?: string;
|
|
127
127
|
idInternoShopify?: string;
|
|
128
128
|
precio: number | null;
|
|
129
129
|
fechaCreacionExterna?: string | null;
|
|
@@ -139,7 +139,7 @@ export type ModifiedOrder = {
|
|
|
139
139
|
observacionesLLegada?: string;
|
|
140
140
|
observaciones?: string;
|
|
141
141
|
direccionSalidaId?: number | null;
|
|
142
|
-
|
|
142
|
+
direccionSalidaPersonalizada?: SellerAddress | null;
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
export interface ModifiedOrderExtended extends ModifiedOrder {
|
|
@@ -469,7 +469,7 @@ export type InsertContentShipmentDetail = {
|
|
|
469
469
|
|
|
470
470
|
type InsertContentShipmentExternal = {
|
|
471
471
|
id_envio_temporal_usuario: number;
|
|
472
|
-
codigo_envio_externo: string;
|
|
472
|
+
codigo_envio_externo: string | undefined;
|
|
473
473
|
id_usuario: number;
|
|
474
474
|
fecha_hora_creacion: string;
|
|
475
475
|
servicio: Type;
|