cardus 0.0.103 → 0.0.106
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 +1370 -0
- package/dist/__tests__/insertTempShipments.test.js +1150 -0
- package/dist/index.js +109 -105
- package/dist/jest.config.js +18 -0
- package/index.ts +147 -157
- package/jest.config.js +17 -0
- package/package.json +3 -1
- package/types/index.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -33,21 +33,6 @@ class IntegrationManager {
|
|
|
33
33
|
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
|
-
this.insertTempShipmentGroupLine = ({ idEnvioTemporal, group }) => {
|
|
37
|
-
// si agrupamos, no deberia de haber mas lineas, pero por si acaso, con el set machacamos lo que pudiera haber -que no deberia haber nada, insisto-
|
|
38
|
-
this.dataToInsert.lines.set(idEnvioTemporal, [
|
|
39
|
-
{
|
|
40
|
-
id_envio: idEnvioTemporal,
|
|
41
|
-
bulto: {
|
|
42
|
-
peso: group.weight,
|
|
43
|
-
alto: group.height,
|
|
44
|
-
ancho: group.width,
|
|
45
|
-
largo: group.length,
|
|
46
|
-
sku_producto: ''
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
]);
|
|
50
|
-
};
|
|
51
36
|
this.services = {
|
|
52
37
|
integrationsService: params.integrationsService,
|
|
53
38
|
addressesService: params.addressesService,
|
|
@@ -105,6 +90,7 @@ class IntegrationManager {
|
|
|
105
90
|
}
|
|
106
91
|
});
|
|
107
92
|
const isPriorityByDefault = yield checkIsPriorityByDefault();
|
|
93
|
+
const abortedTempShipments = [];
|
|
108
94
|
const insertOrdersResult = yield new this.executionManager({
|
|
109
95
|
arrayParams: filteredOrders,
|
|
110
96
|
executable: (order) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -120,7 +106,7 @@ class IntegrationManager {
|
|
|
120
106
|
shipmentType: this.shipmentType,
|
|
121
107
|
agencyId,
|
|
122
108
|
warehouseId,
|
|
123
|
-
sellerAddress,
|
|
109
|
+
sellerAddress: direccionSalida !== null && direccionSalida !== void 0 ? direccionSalida : sellerAddress,
|
|
124
110
|
idUsuario,
|
|
125
111
|
findNextPickupDate: this.findNextPickupDate,
|
|
126
112
|
countriesService: this.services.countriesService,
|
|
@@ -130,16 +116,11 @@ class IntegrationManager {
|
|
|
130
116
|
if (!idEnvioTemporal) {
|
|
131
117
|
throw new Error('Temp shipments could not be created');
|
|
132
118
|
}
|
|
133
|
-
yield this.insertQuantityRelatedLines({
|
|
134
|
-
|
|
119
|
+
const { shipmentDetails, bultosYCantidades } = yield this.insertQuantityRelatedLines({
|
|
120
|
+
parsedOrder: Object.assign(Object.assign({}, parsedOrder), { idEnvioTemporal }),
|
|
135
121
|
idUsuario,
|
|
136
122
|
crearBulto,
|
|
137
|
-
group
|
|
138
|
-
warehouseId,
|
|
139
|
-
shouldFindWarehouseSkus
|
|
140
|
-
});
|
|
141
|
-
const shipmentDetails = this.dataToInsert.details.filter(({ id_envio }) => {
|
|
142
|
-
return id_envio === order.idEnvioTemporal;
|
|
123
|
+
group
|
|
143
124
|
});
|
|
144
125
|
const { partialTempShipmentModified, packagesModified } = yield this.getModifiedOrderBasedOnRules({
|
|
145
126
|
defaultAgencyId: agencyId,
|
|
@@ -161,26 +142,56 @@ class IntegrationManager {
|
|
|
161
142
|
id_envio: idEnvioTemporal,
|
|
162
143
|
id_usuario: idUsuario
|
|
163
144
|
});
|
|
145
|
+
abortedTempShipments.push(idEnvioTemporal);
|
|
164
146
|
this.dataToInsert.lines.delete(idEnvioTemporal);
|
|
165
147
|
return;
|
|
166
148
|
}
|
|
167
149
|
if (isTempShipmentModified) {
|
|
168
150
|
delete partialTempShipmentModified.abort_creation; // por si acaso
|
|
169
|
-
yield integrationsService.updateTempShimpment(Object.assign({ id_envio: idEnvioTemporal }, partialTempShipmentModified));
|
|
151
|
+
yield integrationsService.updateTempShimpment(Object.assign({ id_envio: idEnvioTemporal, id_usuario: idUsuario }, partialTempShipmentModified));
|
|
170
152
|
}
|
|
171
153
|
if (arePackagesModified) {
|
|
172
154
|
this.dataToInsert.lines.set(idEnvioTemporal, packagesModified);
|
|
173
155
|
}
|
|
156
|
+
// para cuando el usuario quiere mapear su sku con la referencia que tenga en almacen
|
|
157
|
+
if (shouldFindWarehouseSkus) {
|
|
158
|
+
const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce((acc, curr) => {
|
|
159
|
+
var _a;
|
|
160
|
+
const tempShipmentId = curr === null || curr === void 0 ? void 0 : curr.idEnvioTemporal;
|
|
161
|
+
if (!tempShipmentId)
|
|
162
|
+
return acc;
|
|
163
|
+
(_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
|
|
164
|
+
acc[tempShipmentId].push(curr);
|
|
165
|
+
return acc;
|
|
166
|
+
}, {});
|
|
167
|
+
yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_b) => __awaiter(this, [_b], void 0, function* ([tempShipmentId, bultosYCantidades]) {
|
|
168
|
+
const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
|
|
169
|
+
idUsuario,
|
|
170
|
+
warehouseId,
|
|
171
|
+
bultosYCantidades
|
|
172
|
+
});
|
|
173
|
+
if (json_referencias_cantidades.length > 0) {
|
|
174
|
+
this.dataToInsert.jsonQuantityReferences.push({
|
|
175
|
+
id_envio: Number(tempShipmentId),
|
|
176
|
+
json_referencias_cantidades
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
})));
|
|
180
|
+
}
|
|
181
|
+
// external
|
|
174
182
|
this.insertExternalShipment({
|
|
175
183
|
idUsuario,
|
|
176
184
|
order: parsedOrder,
|
|
177
185
|
idEnvioTemporal
|
|
178
186
|
});
|
|
187
|
+
// details
|
|
188
|
+
this.dataToInsert.details.push(...shipmentDetails);
|
|
179
189
|
return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
|
|
180
190
|
}),
|
|
181
191
|
regularExecutionTime: 8000, // ms
|
|
182
192
|
initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
|
|
183
193
|
}).upload();
|
|
194
|
+
// content (dentro de esta funcion coge los detalles y evoluciona a partir de ahi)
|
|
184
195
|
yield this.insertUserDefaultConfigurationContent({
|
|
185
196
|
user,
|
|
186
197
|
countryName: country.nombre_pais_en
|
|
@@ -305,7 +316,7 @@ class IntegrationManager {
|
|
|
305
316
|
});
|
|
306
317
|
}
|
|
307
318
|
insertQuantityRelatedLines(_a) {
|
|
308
|
-
return __awaiter(this, arguments, void 0, function* ({
|
|
319
|
+
return __awaiter(this, arguments, void 0, function* ({ parsedOrder, idUsuario, crearBulto, group }) {
|
|
309
320
|
/*
|
|
310
321
|
En esta funcion se calculan los records a incluir en la tabla de detalles y en las de lineas
|
|
311
322
|
Los detalles, es facil, una por cada bulto (aqui no hay ni "agrupar" ni nada de eso, una por cada bulto y ya esta)
|
|
@@ -316,6 +327,7 @@ class IntegrationManager {
|
|
|
316
327
|
*/
|
|
317
328
|
var _b;
|
|
318
329
|
const { integrationsService } = this.services;
|
|
330
|
+
const shipmentDetails = [];
|
|
319
331
|
const shouldGetMeasuresFromGroupBeingOneLine = !!((_b = (yield integrationsService.getDefaultIntegrationsData({
|
|
320
332
|
id_usuario: idUsuario,
|
|
321
333
|
id_integracion: this.integrationType
|
|
@@ -338,92 +350,84 @@ class IntegrationManager {
|
|
|
338
350
|
}
|
|
339
351
|
return null;
|
|
340
352
|
});
|
|
341
|
-
yield Promise.allSettled(
|
|
342
353
|
// por cada pedido/envio
|
|
343
|
-
|
|
344
|
-
|
|
354
|
+
const { idEnvioTemporal, lineas } = parsedOrder;
|
|
355
|
+
// hacemos esto primero, todavia no sabemos si vamos a agrupar (porque necesitamos crear el bulto para eso, ya que la "cantidad" podria influir)
|
|
356
|
+
const bultosYCantidades = (yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
|
|
357
|
+
const bultoYCantidad = yield createBultoFromLine({
|
|
358
|
+
line,
|
|
359
|
+
idEnvioTemporal
|
|
360
|
+
});
|
|
361
|
+
return bultoYCantidad;
|
|
362
|
+
})))).filter(Boolean);
|
|
363
|
+
// sacamos todos los bultos (y cantidad)
|
|
364
|
+
yield Promise.allSettled(bultosYCantidades.map((bultoYCantidad) => __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
var _d;
|
|
366
|
+
if (!bultoYCantidad)
|
|
345
367
|
return;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
//
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
368
|
+
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } = bultoYCantidad;
|
|
369
|
+
// metemos los detalles siempre
|
|
370
|
+
shipmentDetails.push({
|
|
371
|
+
id_envio: idEnvioTemporal,
|
|
372
|
+
bulto,
|
|
373
|
+
cantidad
|
|
374
|
+
});
|
|
375
|
+
// Debe agrupar si:
|
|
376
|
+
// 1. grouped es 1 + hay más de una línea
|
|
377
|
+
// 2. grouped es 1 + hay una línea + configuración integraciones tiene el campo dimensiones_medidas_configuradas a 1 (osea, que queremos que coja las dimensiones del bulto, aunque sea una sola linea)
|
|
378
|
+
// 3. grouped es 1 + hay una lines + cantidad es mayor que 1
|
|
379
|
+
const shouldGroup = (group === null || group === void 0 ? void 0 : group.grouped) === 1 &&
|
|
380
|
+
(lineas.length > 1 ||
|
|
381
|
+
(lineas.length === 1 && shouldGetMeasuresFromGroupBeingOneLine) ||
|
|
382
|
+
(lineas.length === 1 && Number(cantidad) > 1));
|
|
383
|
+
// si agrupamos, metemos solo una linea en "lineas" y cogemos las dimensiones y peso de "group" (lo que el usuario tenga por defecto)
|
|
384
|
+
if (shouldGroup) {
|
|
385
|
+
// si agrupamos, no deberia de haber mas lineas, pero por si acaso, con el set machacamos lo que pudiera haber -que no deberia haber nada, insisto-
|
|
386
|
+
this.dataToInsert.lines.set(idEnvioTemporal, [
|
|
387
|
+
{
|
|
388
|
+
id_envio: idEnvioTemporal,
|
|
389
|
+
bulto: {
|
|
390
|
+
peso: group.weight,
|
|
391
|
+
alto: group.height,
|
|
392
|
+
ancho: group.width,
|
|
393
|
+
largo: group.length,
|
|
394
|
+
sku_producto: ''
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
]);
|
|
398
|
+
// si no agrupamos, cogemos el peso y dimensiones del peso mismo
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
// lo de "forzarAgrupamientoDeLinea" se hizo solo para un usuario (Pegaso) que ya ni siquiera esta. Lo que hace es que siempre mete una linea, sin tener en cuenta la cantidad, pero con las dimensiones que les hemos preparado para ese bulto (que es una suma de todos los bultos reales... un chanchullo)
|
|
402
|
+
const tempShipmentLines = [];
|
|
403
|
+
if (forzarAgrupamientoDeLinea) {
|
|
404
|
+
tempShipmentLines.push({
|
|
405
|
+
id_envio: idEnvioTemporal,
|
|
406
|
+
bulto
|
|
407
|
+
});
|
|
408
|
+
// y esto para todo el resto de usuarios
|
|
378
409
|
}
|
|
379
410
|
else {
|
|
380
|
-
//
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
// y esto para todo el resto de usuarios
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
// creamos una linea por cada una de las unidades de "cantidad" (si cantidad es 5, pues 5 lineas -todas iguales, con el peso y medidas del bulto-)
|
|
391
|
-
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
392
|
-
const linesToAdd = arrayFake.map(() => ({
|
|
393
|
-
id_envio: idEnvioTemporal,
|
|
394
|
-
bulto
|
|
395
|
-
}));
|
|
396
|
-
tempShipmentLines.push(...linesToAdd);
|
|
397
|
-
}
|
|
398
|
-
this.dataToInsert.lines.set(idEnvioTemporal, tempShipmentLines);
|
|
411
|
+
// creamos una linea por cada una de las unidades de "cantidad" (si cantidad es 5, pues 5 lineas -todas iguales, con el peso y medidas del bulto-)
|
|
412
|
+
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
413
|
+
const linesToAdd = arrayFake.map(() => ({
|
|
414
|
+
id_envio: idEnvioTemporal,
|
|
415
|
+
bulto
|
|
416
|
+
}));
|
|
417
|
+
tempShipmentLines.push(...linesToAdd);
|
|
399
418
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (!tempShipmentId)
|
|
406
|
-
return acc;
|
|
407
|
-
(_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
|
|
408
|
-
acc[tempShipmentId].push(curr);
|
|
409
|
-
return acc;
|
|
410
|
-
}, {});
|
|
411
|
-
yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_e) => __awaiter(this, [_e], void 0, function* ([tempShipmentId, bultosYCantidades]) {
|
|
412
|
-
const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
|
|
413
|
-
idUsuario,
|
|
414
|
-
warehouseId,
|
|
415
|
-
bultosYCantidades
|
|
416
|
-
});
|
|
417
|
-
if (json_referencias_cantidades.length > 0) {
|
|
418
|
-
this.dataToInsert.jsonQuantityReferences.push({
|
|
419
|
-
id_envio: Number(tempShipmentId),
|
|
420
|
-
json_referencias_cantidades
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
})));
|
|
419
|
+
if (this.dataToInsert.lines.has(idEnvioTemporal)) {
|
|
420
|
+
this.dataToInsert.lines.set(idEnvioTemporal, [
|
|
421
|
+
...((_d = this.dataToInsert.lines.get(idEnvioTemporal)) !== null && _d !== void 0 ? _d : []),
|
|
422
|
+
...tempShipmentLines
|
|
423
|
+
]);
|
|
424
424
|
}
|
|
425
|
-
|
|
425
|
+
else {
|
|
426
|
+
this.dataToInsert.lines.set(idEnvioTemporal, tempShipmentLines);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
426
429
|
})));
|
|
430
|
+
return { shipmentDetails, bultosYCantidades };
|
|
427
431
|
});
|
|
428
432
|
}
|
|
429
433
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @type {import('jest').Config} */
|
|
3
|
+
module.exports = {
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
roots: ['<rootDir>/__tests__'],
|
|
7
|
+
testMatch: ['**/*.test.ts'],
|
|
8
|
+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
|
|
9
|
+
modulePathIgnorePatterns: ['<rootDir>/dist/'],
|
|
10
|
+
transform: {
|
|
11
|
+
'^.+\\.tsx?$': [
|
|
12
|
+
'ts-jest',
|
|
13
|
+
{
|
|
14
|
+
diagnostics: false
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
};
|