cardus 0.0.52 → 0.0.54
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 +37 -37
- package/dist/insertTempShipment/index.js +5 -1
- package/index.ts +44 -56
- package/insertTempShipment/index.ts +6 -1
- package/package.json +1 -1
- package/types/index.ts +7 -2
package/dist/index.js
CHANGED
|
@@ -17,28 +17,7 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
17
17
|
const insertTempShipment_1 = require("./insertTempShipment");
|
|
18
18
|
class IntegrationManager {
|
|
19
19
|
constructor(params) {
|
|
20
|
-
this.
|
|
21
|
-
const idEnvioTemporal = yield this.insertTempShipment({
|
|
22
|
-
order,
|
|
23
|
-
agencyId,
|
|
24
|
-
warehouseId,
|
|
25
|
-
sellerAddress,
|
|
26
|
-
idUsuario,
|
|
27
|
-
isPriority
|
|
28
|
-
});
|
|
29
|
-
if (!idEnvioTemporal)
|
|
30
|
-
throw new Error('Temp shipments could not be created');
|
|
31
|
-
this.insertExternalShipment({
|
|
32
|
-
idUsuario,
|
|
33
|
-
order,
|
|
34
|
-
idEnvioTemporal
|
|
35
|
-
});
|
|
36
|
-
const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
|
|
37
|
-
if (grouped)
|
|
38
|
-
yield this.insertTempShipmentLines({ idEnvioTemporal, group });
|
|
39
|
-
return Object.assign(order, { idEnvioTemporal });
|
|
40
|
-
});
|
|
41
|
-
this.insertTempShipment = (_b) => __awaiter(this, [_b], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, isPriority }) {
|
|
20
|
+
this.insertTempShipment = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, isPriority }) {
|
|
42
21
|
const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
|
|
43
22
|
order,
|
|
44
23
|
shipmentType: this.shipmentType,
|
|
@@ -68,8 +47,8 @@ class IntegrationManager {
|
|
|
68
47
|
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
69
48
|
});
|
|
70
49
|
};
|
|
71
|
-
this.
|
|
72
|
-
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
50
|
+
this.insertTempShipmentGroupLine = ({ idEnvioTemporal, group }) => {
|
|
51
|
+
const grouped = (group === null || group === void 0 ? void 0 : group.grouped) === 1 || (group === null || group === void 0 ? void 0 : group.grouped) === '1';
|
|
73
52
|
if (grouped) {
|
|
74
53
|
this.dataToInsert.lines.push({
|
|
75
54
|
id_envio: idEnvioTemporal,
|
|
@@ -81,7 +60,7 @@ class IntegrationManager {
|
|
|
81
60
|
}
|
|
82
61
|
});
|
|
83
62
|
}
|
|
84
|
-
}
|
|
63
|
+
};
|
|
85
64
|
this.services = {
|
|
86
65
|
integrationsService: params.integrationsService,
|
|
87
66
|
addressesService: params.addressesService,
|
|
@@ -106,7 +85,6 @@ class IntegrationManager {
|
|
|
106
85
|
insertTempShipments(_a) {
|
|
107
86
|
return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
|
|
108
87
|
const user = yield this.services.usersService.obtenerUsuarioId(idUsuario);
|
|
109
|
-
const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
|
|
110
88
|
const { integrationsService, addressesService } = this.services;
|
|
111
89
|
// esto hay que pasarlo ya en los parametros
|
|
112
90
|
const sellerAddress = warehouseId > 0
|
|
@@ -137,7 +115,7 @@ class IntegrationManager {
|
|
|
137
115
|
const parsedOrder = yield modificarOrdenOriginal({
|
|
138
116
|
originalOrder: order
|
|
139
117
|
});
|
|
140
|
-
|
|
118
|
+
const idEnvioTemporal = yield this.insertTempShipment({
|
|
141
119
|
order: parsedOrder,
|
|
142
120
|
agencyId: yield this.getAgencyIdForTempShipment({
|
|
143
121
|
defaultAgencyId: agencyId,
|
|
@@ -149,9 +127,16 @@ class IntegrationManager {
|
|
|
149
127
|
warehouseId,
|
|
150
128
|
sellerAddress,
|
|
151
129
|
idUsuario,
|
|
152
|
-
group,
|
|
153
130
|
isPriority: isPriorityByDefault
|
|
154
131
|
});
|
|
132
|
+
if (!idEnvioTemporal) {
|
|
133
|
+
throw new Error('Temp shipments could not be created');
|
|
134
|
+
}
|
|
135
|
+
this.insertExternalShipment({
|
|
136
|
+
idUsuario,
|
|
137
|
+
order: parsedOrder,
|
|
138
|
+
idEnvioTemporal
|
|
139
|
+
});
|
|
155
140
|
}),
|
|
156
141
|
regularExecutionTime: 8000, // ms
|
|
157
142
|
initialBatchQuantity: 5 // de cinco en cinco
|
|
@@ -164,7 +149,7 @@ class IntegrationManager {
|
|
|
164
149
|
orders: successfullShipments,
|
|
165
150
|
idUsuario,
|
|
166
151
|
crearBulto,
|
|
167
|
-
|
|
152
|
+
group
|
|
168
153
|
});
|
|
169
154
|
yield this.insertUserDefaultConfigurationContent({
|
|
170
155
|
user,
|
|
@@ -206,15 +191,21 @@ class IntegrationManager {
|
|
|
206
191
|
});
|
|
207
192
|
}
|
|
208
193
|
insertQuantityRelatedLines(_a) {
|
|
209
|
-
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto,
|
|
194
|
+
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group }) {
|
|
195
|
+
const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
|
|
210
196
|
const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
|
|
211
197
|
const result = yield crearBulto({
|
|
212
198
|
lineItems: { idEnvioTemporal, line },
|
|
213
199
|
idUsuario
|
|
214
200
|
});
|
|
215
|
-
const { bulto, cantidad } = result;
|
|
201
|
+
const { bulto, cantidad, forzarAgrupamientoDeLinea } = result;
|
|
216
202
|
if (cantidad && bulto) {
|
|
217
|
-
return {
|
|
203
|
+
return {
|
|
204
|
+
bulto,
|
|
205
|
+
cantidad,
|
|
206
|
+
idEnvioTemporal,
|
|
207
|
+
forzarAgrupamientoDeLinea: !!forzarAgrupamientoDeLinea
|
|
208
|
+
};
|
|
218
209
|
}
|
|
219
210
|
return null;
|
|
220
211
|
});
|
|
@@ -222,6 +213,9 @@ class IntegrationManager {
|
|
|
222
213
|
orders.forEach(({ idEnvioTemporal, lineas }) => {
|
|
223
214
|
if (!idEnvioTemporal)
|
|
224
215
|
return;
|
|
216
|
+
if (grouped) {
|
|
217
|
+
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
218
|
+
}
|
|
225
219
|
lineas.forEach((line) => {
|
|
226
220
|
const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
|
|
227
221
|
obtenerBultosYCantidades.push(bultoPromise);
|
|
@@ -232,22 +226,28 @@ class IntegrationManager {
|
|
|
232
226
|
bultosYCantidades.forEach((each) => {
|
|
233
227
|
if (!each)
|
|
234
228
|
return;
|
|
235
|
-
const { bulto, cantidad, idEnvioTemporal } = each;
|
|
229
|
+
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } = each;
|
|
236
230
|
try {
|
|
231
|
+
if (!grouped && forzarAgrupamientoDeLinea) {
|
|
232
|
+
this.dataToInsert.lines.push({
|
|
233
|
+
id_envio: idEnvioTemporal,
|
|
234
|
+
bulto
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
237
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
238
238
|
this.dataToInsert.details.push({
|
|
239
239
|
id_envio: idEnvioTemporal,
|
|
240
240
|
bulto,
|
|
241
241
|
cantidad
|
|
242
242
|
});
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
if (!grouped && !forzarAgrupamientoDeLinea) {
|
|
244
|
+
arrayFake.forEach(() => {
|
|
245
245
|
this.dataToInsert.lines.push({
|
|
246
246
|
id_envio: idEnvioTemporal,
|
|
247
247
|
bulto
|
|
248
248
|
});
|
|
249
|
-
}
|
|
250
|
-
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
251
|
}
|
|
252
252
|
catch (e) {
|
|
253
253
|
console.log(e);
|
|
@@ -106,13 +106,17 @@ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ or
|
|
|
106
106
|
id_almacen: warehouseId,
|
|
107
107
|
agencia_envio_integracion: order.agenciaEnvioIntegracion
|
|
108
108
|
});
|
|
109
|
+
const setReferenciaCliente = (order) => ({
|
|
110
|
+
referencia_cliente: order.referenciaCliente || null
|
|
111
|
+
});
|
|
109
112
|
const setters = [
|
|
110
113
|
setDatosVendedor,
|
|
111
114
|
setDatosComprador,
|
|
112
115
|
setUbicacionComprador,
|
|
113
116
|
setReembolso,
|
|
114
117
|
setFechas,
|
|
115
|
-
setBultos
|
|
118
|
+
setBultos,
|
|
119
|
+
setReferenciaCliente
|
|
116
120
|
];
|
|
117
121
|
const dataInsert = (yield setters.reduce((acc, curr) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
122
|
const accumulated = yield acc;
|
package/index.ts
CHANGED
|
@@ -94,7 +94,6 @@ export class IntegrationManager {
|
|
|
94
94
|
modificarOrdenOriginal
|
|
95
95
|
}: InsertParams) {
|
|
96
96
|
const user = await this.services.usersService.obtenerUsuarioId(idUsuario);
|
|
97
|
-
const estaAgrupado = Number(group?.grouped) === 1;
|
|
98
97
|
const { integrationsService, addressesService } = this.services;
|
|
99
98
|
// esto hay que pasarlo ya en los parametros
|
|
100
99
|
const sellerAddress =
|
|
@@ -140,7 +139,7 @@ export class IntegrationManager {
|
|
|
140
139
|
originalOrder: order
|
|
141
140
|
});
|
|
142
141
|
|
|
143
|
-
|
|
142
|
+
const idEnvioTemporal = await this.insertTempShipment({
|
|
144
143
|
order: parsedOrder,
|
|
145
144
|
agencyId: await this.getAgencyIdForTempShipment({
|
|
146
145
|
defaultAgencyId: agencyId,
|
|
@@ -152,9 +151,18 @@ export class IntegrationManager {
|
|
|
152
151
|
warehouseId,
|
|
153
152
|
sellerAddress,
|
|
154
153
|
idUsuario,
|
|
155
|
-
group,
|
|
156
154
|
isPriority: isPriorityByDefault
|
|
157
155
|
});
|
|
156
|
+
|
|
157
|
+
if (!idEnvioTemporal) {
|
|
158
|
+
throw new Error('Temp shipments could not be created');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.insertExternalShipment({
|
|
162
|
+
idUsuario,
|
|
163
|
+
order: parsedOrder,
|
|
164
|
+
idEnvioTemporal
|
|
165
|
+
});
|
|
158
166
|
},
|
|
159
167
|
regularExecutionTime: 8000, // ms
|
|
160
168
|
initialBatchQuantity: 5 // de cinco en cinco
|
|
@@ -169,7 +177,7 @@ export class IntegrationManager {
|
|
|
169
177
|
orders: successfullShipments,
|
|
170
178
|
idUsuario,
|
|
171
179
|
crearBulto,
|
|
172
|
-
|
|
180
|
+
group
|
|
173
181
|
});
|
|
174
182
|
|
|
175
183
|
await this.insertUserDefaultConfigurationContent({
|
|
@@ -239,46 +247,6 @@ export class IntegrationManager {
|
|
|
239
247
|
}
|
|
240
248
|
}
|
|
241
249
|
|
|
242
|
-
insertOrder = async ({
|
|
243
|
-
order,
|
|
244
|
-
agencyId,
|
|
245
|
-
warehouseId,
|
|
246
|
-
sellerAddress,
|
|
247
|
-
idUsuario,
|
|
248
|
-
group,
|
|
249
|
-
isPriority
|
|
250
|
-
}: {
|
|
251
|
-
order: ModifiedOrder;
|
|
252
|
-
agencyId: number;
|
|
253
|
-
warehouseId: number;
|
|
254
|
-
sellerAddress: SellerAddress;
|
|
255
|
-
idUsuario: number;
|
|
256
|
-
group: Group;
|
|
257
|
-
isPriority: IsPriority;
|
|
258
|
-
}): Promise<ModifiedOrderExtended> => {
|
|
259
|
-
const idEnvioTemporal = await this.insertTempShipment({
|
|
260
|
-
order,
|
|
261
|
-
agencyId,
|
|
262
|
-
warehouseId,
|
|
263
|
-
sellerAddress,
|
|
264
|
-
idUsuario,
|
|
265
|
-
isPriority
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
if (!idEnvioTemporal)
|
|
269
|
-
throw new Error('Temp shipments could not be created');
|
|
270
|
-
|
|
271
|
-
this.insertExternalShipment({
|
|
272
|
-
idUsuario,
|
|
273
|
-
order,
|
|
274
|
-
idEnvioTemporal
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
const grouped = Number(group?.grouped === 1);
|
|
278
|
-
if (grouped) await this.insertTempShipmentLines({ idEnvioTemporal, group });
|
|
279
|
-
return Object.assign(order, { idEnvioTemporal });
|
|
280
|
-
};
|
|
281
|
-
|
|
282
250
|
insertTempShipment = async ({
|
|
283
251
|
order,
|
|
284
252
|
agencyId,
|
|
@@ -337,15 +305,14 @@ export class IntegrationManager {
|
|
|
337
305
|
});
|
|
338
306
|
};
|
|
339
307
|
|
|
340
|
-
|
|
308
|
+
insertTempShipmentGroupLine = ({
|
|
341
309
|
idEnvioTemporal,
|
|
342
310
|
group
|
|
343
311
|
}: {
|
|
344
312
|
idEnvioTemporal: number;
|
|
345
313
|
group: Group;
|
|
346
314
|
}) => {
|
|
347
|
-
const grouped = group
|
|
348
|
-
|
|
315
|
+
const grouped = group?.grouped === 1 || group?.grouped === '1';
|
|
349
316
|
if (grouped) {
|
|
350
317
|
this.dataToInsert.lines.push({
|
|
351
318
|
id_envio: idEnvioTemporal,
|
|
@@ -363,19 +330,22 @@ export class IntegrationManager {
|
|
|
363
330
|
orders,
|
|
364
331
|
idUsuario,
|
|
365
332
|
crearBulto,
|
|
366
|
-
|
|
333
|
+
group
|
|
367
334
|
}: {
|
|
368
335
|
orders: ModifiedOrderExtended[];
|
|
369
336
|
idUsuario: number;
|
|
370
337
|
crearBulto: CrearBulto;
|
|
371
|
-
|
|
338
|
+
group: Group;
|
|
372
339
|
}) {
|
|
373
340
|
type BultoYCantidad = {
|
|
374
341
|
bulto: Bulto['bulto'];
|
|
375
342
|
cantidad: Bulto['cantidad'];
|
|
376
343
|
idEnvioTemporal: number;
|
|
344
|
+
forzarAgrupamientoDeLinea: boolean;
|
|
377
345
|
};
|
|
378
346
|
|
|
347
|
+
const grouped = Number(group?.grouped === 1);
|
|
348
|
+
|
|
379
349
|
const createBultoFromLine = async ({
|
|
380
350
|
line,
|
|
381
351
|
idEnvioTemporal
|
|
@@ -387,10 +357,15 @@ export class IntegrationManager {
|
|
|
387
357
|
lineItems: { idEnvioTemporal, line },
|
|
388
358
|
idUsuario
|
|
389
359
|
});
|
|
390
|
-
const { bulto, cantidad } = result;
|
|
360
|
+
const { bulto, cantidad, forzarAgrupamientoDeLinea } = result;
|
|
391
361
|
|
|
392
362
|
if (cantidad && bulto) {
|
|
393
|
-
return {
|
|
363
|
+
return {
|
|
364
|
+
bulto,
|
|
365
|
+
cantidad,
|
|
366
|
+
idEnvioTemporal,
|
|
367
|
+
forzarAgrupamientoDeLinea: !!forzarAgrupamientoDeLinea
|
|
368
|
+
};
|
|
394
369
|
}
|
|
395
370
|
return null;
|
|
396
371
|
};
|
|
@@ -399,6 +374,11 @@ export class IntegrationManager {
|
|
|
399
374
|
|
|
400
375
|
orders.forEach(({ idEnvioTemporal, lineas }) => {
|
|
401
376
|
if (!idEnvioTemporal) return;
|
|
377
|
+
|
|
378
|
+
if (grouped) {
|
|
379
|
+
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
380
|
+
}
|
|
381
|
+
|
|
402
382
|
lineas.forEach((line) => {
|
|
403
383
|
const bultoPromise = createBultoFromLine({ line, idEnvioTemporal });
|
|
404
384
|
obtenerBultosYCantidades.push(bultoPromise);
|
|
@@ -410,8 +390,16 @@ export class IntegrationManager {
|
|
|
410
390
|
|
|
411
391
|
bultosYCantidades.forEach((each) => {
|
|
412
392
|
if (!each) return;
|
|
413
|
-
const { bulto, cantidad, idEnvioTemporal } =
|
|
393
|
+
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } =
|
|
394
|
+
each;
|
|
414
395
|
try {
|
|
396
|
+
if (!grouped && forzarAgrupamientoDeLinea) {
|
|
397
|
+
this.dataToInsert.lines.push({
|
|
398
|
+
id_envio: idEnvioTemporal,
|
|
399
|
+
bulto
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
415
403
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
416
404
|
|
|
417
405
|
this.dataToInsert.details.push({
|
|
@@ -420,14 +408,14 @@ export class IntegrationManager {
|
|
|
420
408
|
cantidad
|
|
421
409
|
});
|
|
422
410
|
|
|
423
|
-
|
|
424
|
-
|
|
411
|
+
if (!grouped && !forzarAgrupamientoDeLinea) {
|
|
412
|
+
arrayFake.forEach(() => {
|
|
425
413
|
this.dataToInsert.lines.push({
|
|
426
414
|
id_envio: idEnvioTemporal,
|
|
427
415
|
bulto
|
|
428
416
|
});
|
|
429
|
-
}
|
|
430
|
-
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
431
419
|
} catch (e) {
|
|
432
420
|
console.log(e);
|
|
433
421
|
}
|
|
@@ -154,13 +154,18 @@ export const cookTempShipment = async ({
|
|
|
154
154
|
agencia_envio_integracion: order.agenciaEnvioIntegracion
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
+
const setReferenciaCliente = (order: ModifiedOrder) => ({
|
|
158
|
+
referencia_cliente: order.referenciaCliente || null
|
|
159
|
+
});
|
|
160
|
+
|
|
157
161
|
const setters = [
|
|
158
162
|
setDatosVendedor,
|
|
159
163
|
setDatosComprador,
|
|
160
164
|
setUbicacionComprador,
|
|
161
165
|
setReembolso,
|
|
162
166
|
setFechas,
|
|
163
|
-
setBultos
|
|
167
|
+
setBultos,
|
|
168
|
+
setReferenciaCliente
|
|
164
169
|
];
|
|
165
170
|
|
|
166
171
|
const dataInsert = (await setters.reduce(async (acc, curr) => {
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -93,6 +93,7 @@ export type Bulto = {
|
|
|
93
93
|
nombre_producto: string | null;
|
|
94
94
|
};
|
|
95
95
|
cantidad: number;
|
|
96
|
+
forzarAgrupamientoDeLinea: boolean;
|
|
96
97
|
};
|
|
97
98
|
|
|
98
99
|
export type ModifiedOrder = {
|
|
@@ -117,6 +118,7 @@ export type ModifiedOrder = {
|
|
|
117
118
|
isPriority: 0 | 1;
|
|
118
119
|
idCarrier?: number | null;
|
|
119
120
|
agenciaEnvioIntegracion: string | null;
|
|
121
|
+
referenciaCliente?: string;
|
|
120
122
|
};
|
|
121
123
|
|
|
122
124
|
export interface ModifiedOrderExtended extends ModifiedOrder {
|
|
@@ -128,7 +130,7 @@ type FetchAllOrders = () => Promise<OriginalOrder[]>;
|
|
|
128
130
|
export type CrearBulto = (params: {
|
|
129
131
|
lineItems: { idEnvioTemporal: number; line: AnyObject };
|
|
130
132
|
idUsuario: number;
|
|
131
|
-
}) => Promise<Bulto
|
|
133
|
+
}) => Promise<Bulto>;
|
|
132
134
|
|
|
133
135
|
type ModificarOrdenOriginal = (param: {
|
|
134
136
|
originalOrder: OriginalOrder;
|
|
@@ -173,7 +175,10 @@ export type IntegrationsService = {
|
|
|
173
175
|
idUsuario: number
|
|
174
176
|
) => Promise<boolean>;
|
|
175
177
|
|
|
176
|
-
insertTempShipment: (
|
|
178
|
+
insertTempShipment: (
|
|
179
|
+
params: Shipment,
|
|
180
|
+
check?: boolean
|
|
181
|
+
) => Promise<number | false>;
|
|
177
182
|
|
|
178
183
|
insertExternalShipment: (params: {
|
|
179
184
|
id_envio_temporal_usuario: number;
|