cardus 0.0.84 → 0.0.85
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 +56 -6
- package/index.ts +91 -14
- package/package.json +1 -1
- package/types/index.ts +31 -1
package/dist/index.js
CHANGED
|
@@ -56,7 +56,8 @@ class IntegrationManager {
|
|
|
56
56
|
peso: group.weight,
|
|
57
57
|
alto: group.height,
|
|
58
58
|
ancho: group.width,
|
|
59
|
-
largo: group.length
|
|
59
|
+
largo: group.length,
|
|
60
|
+
sku_producto: ''
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
63
|
}
|
|
@@ -68,13 +69,15 @@ class IntegrationManager {
|
|
|
68
69
|
configurationService: params.configurationService,
|
|
69
70
|
usersService: params.usersService,
|
|
70
71
|
customizationService: params.customizationService,
|
|
71
|
-
llmAPIService: params.llmAPIService
|
|
72
|
+
llmAPIService: params.llmAPIService,
|
|
73
|
+
warehouseService: params.warehouseService
|
|
72
74
|
};
|
|
73
75
|
this.dataToInsert = {
|
|
74
76
|
lines: [],
|
|
75
77
|
contents: [],
|
|
76
78
|
details: [],
|
|
77
|
-
externals: []
|
|
79
|
+
externals: [],
|
|
80
|
+
jsonQuantityReferences: []
|
|
78
81
|
};
|
|
79
82
|
this.integrationType = params.integrationType;
|
|
80
83
|
this.shipmentType = params.shipmentType;
|
|
@@ -150,7 +153,8 @@ class IntegrationManager {
|
|
|
150
153
|
orders: successfullShipments,
|
|
151
154
|
idUsuario,
|
|
152
155
|
crearBulto,
|
|
153
|
-
group
|
|
156
|
+
group,
|
|
157
|
+
warehouseId
|
|
154
158
|
});
|
|
155
159
|
yield this.insertUserDefaultConfigurationContent({
|
|
156
160
|
user,
|
|
@@ -182,7 +186,8 @@ class IntegrationManager {
|
|
|
182
186
|
integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines),
|
|
183
187
|
integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details),
|
|
184
188
|
integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents),
|
|
185
|
-
integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals)
|
|
189
|
+
integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals),
|
|
190
|
+
integrationsService.insertTempShipmentMultipleJsonQuantityReferences(this.dataToInsert.jsonQuantityReferences)
|
|
186
191
|
]);
|
|
187
192
|
return {
|
|
188
193
|
filteredOrders,
|
|
@@ -259,8 +264,32 @@ class IntegrationManager {
|
|
|
259
264
|
}
|
|
260
265
|
});
|
|
261
266
|
}
|
|
267
|
+
createJsonQuantityReferencesFromLines(_a) {
|
|
268
|
+
return __awaiter(this, arguments, void 0, function* ({ warehouseId, bultosYCantidades }) {
|
|
269
|
+
if (warehouseId) {
|
|
270
|
+
const json_referencias_cantidades = (yield Promise.all(bultosYCantidades.map((each) => __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
const cantidad = each === null || each === void 0 ? void 0 : each.cantidad;
|
|
272
|
+
const sku = each === null || each === void 0 ? void 0 : each.bulto.sku_producto;
|
|
273
|
+
if (!cantidad || !sku)
|
|
274
|
+
return [];
|
|
275
|
+
const references = yield this.services.warehouseService.getProductReferenceFromSku(sku);
|
|
276
|
+
const reference = references === null || references === void 0 ? void 0 : references[0];
|
|
277
|
+
if (!(reference === null || reference === void 0 ? void 0 : reference.id_referencia))
|
|
278
|
+
return [];
|
|
279
|
+
return Array.from({ length: cantidad }, () => ({
|
|
280
|
+
id_caja: -1,
|
|
281
|
+
referencias: {
|
|
282
|
+
[reference.id_referencia]: 1
|
|
283
|
+
}
|
|
284
|
+
}));
|
|
285
|
+
})))).flat();
|
|
286
|
+
return json_referencias_cantidades;
|
|
287
|
+
}
|
|
288
|
+
return [];
|
|
289
|
+
});
|
|
290
|
+
}
|
|
262
291
|
insertQuantityRelatedLines(_a) {
|
|
263
|
-
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group }) {
|
|
292
|
+
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group, warehouseId }) {
|
|
264
293
|
/*
|
|
265
294
|
basicamente la logica es:
|
|
266
295
|
1 - si esta agrupado, crea una linea por cada pedido
|
|
@@ -298,6 +327,27 @@ class IntegrationManager {
|
|
|
298
327
|
});
|
|
299
328
|
let bultosYCantidades = yield Promise.all(obtenerBultosYCantidades);
|
|
300
329
|
bultosYCantidades = bultosYCantidades.filter(Boolean);
|
|
330
|
+
const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce((acc, curr) => {
|
|
331
|
+
var _a;
|
|
332
|
+
const tempShipmentId = curr === null || curr === void 0 ? void 0 : curr.idEnvioTemporal;
|
|
333
|
+
if (!tempShipmentId)
|
|
334
|
+
return acc;
|
|
335
|
+
(_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
|
|
336
|
+
acc[tempShipmentId].push(curr);
|
|
337
|
+
return acc;
|
|
338
|
+
}, {});
|
|
339
|
+
yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
|
|
340
|
+
const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
|
|
341
|
+
warehouseId,
|
|
342
|
+
bultosYCantidades
|
|
343
|
+
});
|
|
344
|
+
if (json_referencias_cantidades.length > 0) {
|
|
345
|
+
this.dataToInsert.jsonQuantityReferences.push({
|
|
346
|
+
id_envio: Number(tempShipmentId),
|
|
347
|
+
json_referencias_cantidades
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
})));
|
|
301
351
|
bultosYCantidades.forEach((each) => {
|
|
302
352
|
if (!each)
|
|
303
353
|
return;
|
package/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
UsersService,
|
|
16
16
|
IntegrationsService,
|
|
17
17
|
LlmAPIService,
|
|
18
|
+
WarehouseService,
|
|
18
19
|
Type,
|
|
19
20
|
SellerAddress,
|
|
20
21
|
OriginalOrder,
|
|
@@ -27,7 +28,9 @@ import {
|
|
|
27
28
|
CustomizationService,
|
|
28
29
|
InsertContentShipmentLine,
|
|
29
30
|
Bulto,
|
|
30
|
-
DataToInsert
|
|
31
|
+
DataToInsert,
|
|
32
|
+
BultoYCantidad,
|
|
33
|
+
JsonReferenciasCantidades
|
|
31
34
|
} from './types';
|
|
32
35
|
|
|
33
36
|
interface Services {
|
|
@@ -38,6 +41,7 @@ interface Services {
|
|
|
38
41
|
usersService: UsersService;
|
|
39
42
|
customizationService: CustomizationService;
|
|
40
43
|
llmAPIService: LlmAPIService;
|
|
44
|
+
warehouseService: WarehouseService;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
export class IntegrationManager {
|
|
@@ -59,6 +63,7 @@ export class IntegrationManager {
|
|
|
59
63
|
usersService: UsersService;
|
|
60
64
|
customizationService: CustomizationService;
|
|
61
65
|
llmAPIService: LlmAPIService;
|
|
66
|
+
warehouseService: WarehouseService;
|
|
62
67
|
type: Type;
|
|
63
68
|
integrationType: IntegrationType;
|
|
64
69
|
shipmentType: ShipmentType;
|
|
@@ -73,14 +78,16 @@ export class IntegrationManager {
|
|
|
73
78
|
configurationService: params.configurationService,
|
|
74
79
|
usersService: params.usersService,
|
|
75
80
|
customizationService: params.customizationService,
|
|
76
|
-
llmAPIService: params.llmAPIService
|
|
81
|
+
llmAPIService: params.llmAPIService,
|
|
82
|
+
warehouseService: params.warehouseService
|
|
77
83
|
};
|
|
78
84
|
|
|
79
85
|
this.dataToInsert = {
|
|
80
86
|
lines: [],
|
|
81
87
|
contents: [],
|
|
82
88
|
details: [],
|
|
83
|
-
externals: []
|
|
89
|
+
externals: [],
|
|
90
|
+
jsonQuantityReferences: []
|
|
84
91
|
};
|
|
85
92
|
|
|
86
93
|
this.integrationType = params.integrationType;
|
|
@@ -197,7 +204,8 @@ export class IntegrationManager {
|
|
|
197
204
|
orders: successfullShipments,
|
|
198
205
|
idUsuario,
|
|
199
206
|
crearBulto,
|
|
200
|
-
group
|
|
207
|
+
group,
|
|
208
|
+
warehouseId
|
|
201
209
|
});
|
|
202
210
|
|
|
203
211
|
await this.insertUserDefaultConfigurationContent({
|
|
@@ -248,6 +256,9 @@ export class IntegrationManager {
|
|
|
248
256
|
),
|
|
249
257
|
integrationsService.insertTempShipmentMultipleExternals(
|
|
250
258
|
this.dataToInsert.externals
|
|
259
|
+
),
|
|
260
|
+
integrationsService.insertTempShipmentMultipleJsonQuantityReferences(
|
|
261
|
+
this.dataToInsert.jsonQuantityReferences
|
|
251
262
|
)
|
|
252
263
|
]);
|
|
253
264
|
|
|
@@ -428,30 +439,66 @@ export class IntegrationManager {
|
|
|
428
439
|
peso: group.weight,
|
|
429
440
|
alto: group.height,
|
|
430
441
|
ancho: group.width,
|
|
431
|
-
largo: group.length
|
|
442
|
+
largo: group.length,
|
|
443
|
+
sku_producto: ''
|
|
432
444
|
}
|
|
433
445
|
});
|
|
434
446
|
}
|
|
435
447
|
};
|
|
436
448
|
|
|
449
|
+
async createJsonQuantityReferencesFromLines({
|
|
450
|
+
warehouseId,
|
|
451
|
+
bultosYCantidades
|
|
452
|
+
}: {
|
|
453
|
+
warehouseId: number;
|
|
454
|
+
bultosYCantidades: BultoYCantidad[];
|
|
455
|
+
}): Promise<JsonReferenciasCantidades | []> {
|
|
456
|
+
if (warehouseId) {
|
|
457
|
+
const json_referencias_cantidades = (
|
|
458
|
+
await Promise.all(
|
|
459
|
+
bultosYCantidades.map(async (each) => {
|
|
460
|
+
const cantidad = each?.cantidad;
|
|
461
|
+
const sku = each?.bulto.sku_producto;
|
|
462
|
+
|
|
463
|
+
if (!cantidad || !sku) return [];
|
|
464
|
+
|
|
465
|
+
const references =
|
|
466
|
+
await this.services.warehouseService.getProductReferenceFromSku(
|
|
467
|
+
sku
|
|
468
|
+
);
|
|
469
|
+
const reference = references?.[0];
|
|
470
|
+
|
|
471
|
+
if (!reference?.id_referencia) return [];
|
|
472
|
+
|
|
473
|
+
return Array.from({ length: cantidad }, () => ({
|
|
474
|
+
id_caja: -1,
|
|
475
|
+
referencias: {
|
|
476
|
+
[reference.id_referencia]: 1
|
|
477
|
+
}
|
|
478
|
+
}));
|
|
479
|
+
})
|
|
480
|
+
)
|
|
481
|
+
).flat();
|
|
482
|
+
|
|
483
|
+
return json_referencias_cantidades;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return [];
|
|
487
|
+
}
|
|
488
|
+
|
|
437
489
|
async insertQuantityRelatedLines({
|
|
438
490
|
orders,
|
|
439
491
|
idUsuario,
|
|
440
492
|
crearBulto,
|
|
441
|
-
group
|
|
493
|
+
group,
|
|
494
|
+
warehouseId
|
|
442
495
|
}: {
|
|
443
496
|
orders: ModifiedOrderExtended[];
|
|
444
497
|
idUsuario: number;
|
|
445
498
|
crearBulto: CrearBulto;
|
|
446
499
|
group: Group;
|
|
500
|
+
warehouseId: number;
|
|
447
501
|
}) {
|
|
448
|
-
type BultoYCantidad = {
|
|
449
|
-
bulto: Bulto['bulto'];
|
|
450
|
-
cantidad: Bulto['cantidad'];
|
|
451
|
-
idEnvioTemporal: number;
|
|
452
|
-
forzarAgrupamientoDeLinea: boolean;
|
|
453
|
-
};
|
|
454
|
-
|
|
455
502
|
/*
|
|
456
503
|
basicamente la logica es:
|
|
457
504
|
1 - si esta agrupado, crea una linea por cada pedido
|
|
@@ -503,6 +550,37 @@ export class IntegrationManager {
|
|
|
503
550
|
let bultosYCantidades = await Promise.all(obtenerBultosYCantidades);
|
|
504
551
|
bultosYCantidades = bultosYCantidades.filter(Boolean);
|
|
505
552
|
|
|
553
|
+
const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce<
|
|
554
|
+
Record<number, BultoYCantidad[]>
|
|
555
|
+
>((acc, curr) => {
|
|
556
|
+
const tempShipmentId = curr?.idEnvioTemporal;
|
|
557
|
+
if (!tempShipmentId) return acc;
|
|
558
|
+
|
|
559
|
+
acc[tempShipmentId] ??= [];
|
|
560
|
+
acc[tempShipmentId].push(curr);
|
|
561
|
+
|
|
562
|
+
return acc;
|
|
563
|
+
}, {});
|
|
564
|
+
|
|
565
|
+
await Promise.all(
|
|
566
|
+
Object.entries(bultosYCantidadesGroupedByShipment).map(
|
|
567
|
+
async ([tempShipmentId, bultosYCantidades]) => {
|
|
568
|
+
const json_referencias_cantidades =
|
|
569
|
+
await this.createJsonQuantityReferencesFromLines({
|
|
570
|
+
warehouseId,
|
|
571
|
+
bultosYCantidades
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
if (json_referencias_cantidades.length > 0) {
|
|
575
|
+
this.dataToInsert.jsonQuantityReferences.push({
|
|
576
|
+
id_envio: Number(tempShipmentId),
|
|
577
|
+
json_referencias_cantidades
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
)
|
|
582
|
+
);
|
|
583
|
+
|
|
506
584
|
bultosYCantidades.forEach((each) => {
|
|
507
585
|
if (!each) return;
|
|
508
586
|
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } =
|
|
@@ -513,7 +591,6 @@ export class IntegrationManager {
|
|
|
513
591
|
bulto,
|
|
514
592
|
cantidad
|
|
515
593
|
});
|
|
516
|
-
|
|
517
594
|
if (!grouped && forzarAgrupamientoDeLinea) {
|
|
518
595
|
this.dataToInsert.lines.push({
|
|
519
596
|
id_envio: idEnvioTemporal,
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -104,6 +104,13 @@ export type Bulto = {
|
|
|
104
104
|
forzarAgrupamientoDeLinea: boolean;
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
export type BultoYCantidad = {
|
|
108
|
+
bulto: Bulto['bulto'];
|
|
109
|
+
cantidad: Bulto['cantidad'];
|
|
110
|
+
idEnvioTemporal: number;
|
|
111
|
+
forzarAgrupamientoDeLinea: boolean;
|
|
112
|
+
} | null;
|
|
113
|
+
|
|
107
114
|
export type ModifiedOrder = {
|
|
108
115
|
lineas: Array<InsertContentShipmentLine>;
|
|
109
116
|
codigoPaisLLegada: string | undefined;
|
|
@@ -236,6 +243,9 @@ export type IntegrationsService = {
|
|
|
236
243
|
insertTempShipmentMultipleExternals: (
|
|
237
244
|
externals: DataToInsert['externals']
|
|
238
245
|
) => number | false;
|
|
246
|
+
insertTempShipmentMultipleJsonQuantityReferences: (
|
|
247
|
+
jsonQuantityReferences: DataToInsert['jsonQuantityReferences']
|
|
248
|
+
) => number | false;
|
|
239
249
|
updateTempShimpment: ({
|
|
240
250
|
id_envio,
|
|
241
251
|
id_usuario,
|
|
@@ -253,6 +263,17 @@ export type LlmAPIService = {
|
|
|
253
263
|
) => Promise<string | undefined>;
|
|
254
264
|
};
|
|
255
265
|
|
|
266
|
+
export type WarehouseService = {
|
|
267
|
+
getProductReferenceFromSku: (
|
|
268
|
+
sku: string
|
|
269
|
+
) => Promise<{ id_referencia: number; sku: string }[]>;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export type JsonReferenciasCantidades = Array<{
|
|
273
|
+
id_caja: number;
|
|
274
|
+
referencias: Record<string, number>;
|
|
275
|
+
}>;
|
|
276
|
+
|
|
256
277
|
export type SellerAddress = {
|
|
257
278
|
id_pais: number;
|
|
258
279
|
codigo_postal: string;
|
|
@@ -389,11 +410,15 @@ export type DataToInsert = {
|
|
|
389
410
|
contents: InsertContentShipmentData[];
|
|
390
411
|
details: InsertContentShipmentDetail[];
|
|
391
412
|
externals: InsertContentShipmentExternal[];
|
|
413
|
+
jsonQuantityReferences: InsertContentShipmentJsonQuantityReference[];
|
|
392
414
|
};
|
|
393
415
|
|
|
394
416
|
export type InsertContentShipmentLine = {
|
|
395
417
|
id_envio: number;
|
|
396
|
-
bulto: Pick<
|
|
418
|
+
bulto: Pick<
|
|
419
|
+
Bulto['bulto'],
|
|
420
|
+
'peso' | 'alto' | 'ancho' | 'largo' | 'sku_producto'
|
|
421
|
+
>;
|
|
397
422
|
};
|
|
398
423
|
|
|
399
424
|
type InsertContentShipmentData = UserDefaultConfigurationContent & {
|
|
@@ -418,3 +443,8 @@ type InsertContentShipmentExternal = {
|
|
|
418
443
|
id_documento_holded?: string;
|
|
419
444
|
tipo_documento_holded?: string;
|
|
420
445
|
};
|
|
446
|
+
|
|
447
|
+
type InsertContentShipmentJsonQuantityReference = {
|
|
448
|
+
id_envio: number;
|
|
449
|
+
json_referencias_cantidades: JsonReferenciasCantidades;
|
|
450
|
+
};
|