cardus 0.0.55 → 0.0.57
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 +41 -18
- package/index.ts +63 -28
- package/package.json +1 -1
- package/types/index.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -117,13 +117,7 @@ class IntegrationManager {
|
|
|
117
117
|
});
|
|
118
118
|
const idEnvioTemporal = yield this.insertTempShipment({
|
|
119
119
|
order: parsedOrder,
|
|
120
|
-
agencyId
|
|
121
|
-
defaultAgencyId: agencyId,
|
|
122
|
-
userId: idUsuario,
|
|
123
|
-
integrationId: this.integrationType,
|
|
124
|
-
tempShipmentData: parsedOrder,
|
|
125
|
-
sellerAddress
|
|
126
|
-
}),
|
|
120
|
+
agencyId,
|
|
127
121
|
warehouseId,
|
|
128
122
|
sellerAddress,
|
|
129
123
|
idUsuario,
|
|
@@ -137,7 +131,7 @@ class IntegrationManager {
|
|
|
137
131
|
order: parsedOrder,
|
|
138
132
|
idEnvioTemporal
|
|
139
133
|
});
|
|
140
|
-
return Object.assign(parsedOrder, { idEnvioTemporal });
|
|
134
|
+
return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
|
|
141
135
|
}),
|
|
142
136
|
regularExecutionTime: 8000, // ms
|
|
143
137
|
initialBatchQuantity: 5 // de cinco en cinco
|
|
@@ -156,10 +150,33 @@ class IntegrationManager {
|
|
|
156
150
|
user,
|
|
157
151
|
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
|
|
158
152
|
});
|
|
159
|
-
|
|
160
|
-
yield
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
// modificamos la agencia, cuando se tenga que hacer
|
|
154
|
+
yield Promise.allSettled(successfullShipments.map((order) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const shipmentDetails = this.dataToInsert.details.filter(({ id_envio }) => {
|
|
156
|
+
return id_envio === order.idEnvioTemporal;
|
|
157
|
+
});
|
|
158
|
+
const newAgencyId = yield this.getAgencyIdForTempShipment({
|
|
159
|
+
defaultAgencyId: agencyId,
|
|
160
|
+
userId: idUsuario,
|
|
161
|
+
integrationId: this.integrationType,
|
|
162
|
+
tempShipmentData: order,
|
|
163
|
+
sellerAddress,
|
|
164
|
+
shipmentDetails
|
|
165
|
+
});
|
|
166
|
+
if (newAgencyId !== order.agencyId) {
|
|
167
|
+
yield integrationsService.updateTempShimpment({
|
|
168
|
+
id_envio: order.idEnvioTemporal,
|
|
169
|
+
id_usuario: idUsuario,
|
|
170
|
+
id_agencia: newAgencyId
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
})));
|
|
174
|
+
yield Promise.allSettled([
|
|
175
|
+
integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines),
|
|
176
|
+
integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details),
|
|
177
|
+
integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents),
|
|
178
|
+
integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals)
|
|
179
|
+
]);
|
|
163
180
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
164
181
|
});
|
|
165
182
|
}
|
|
@@ -193,6 +210,12 @@ class IntegrationManager {
|
|
|
193
210
|
}
|
|
194
211
|
insertQuantityRelatedLines(_a) {
|
|
195
212
|
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group }) {
|
|
213
|
+
/*
|
|
214
|
+
basicamente la logica es:
|
|
215
|
+
1 - si esta agrupado, crea una linea por cada pedido
|
|
216
|
+
2 - si "forzarAgrupamientoDeLinea" es true, se crea una linea por cada linea
|
|
217
|
+
3- si NO esta agrupado y "forzarAgrupamientoDeLinea" NO es true, se crea una linea por cada unidad de cada linea
|
|
218
|
+
*/
|
|
196
219
|
const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
|
|
197
220
|
const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
|
|
198
221
|
const result = yield crearBulto({
|
|
@@ -229,19 +252,19 @@ class IntegrationManager {
|
|
|
229
252
|
return;
|
|
230
253
|
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } = each;
|
|
231
254
|
try {
|
|
255
|
+
this.dataToInsert.details.push({
|
|
256
|
+
id_envio: idEnvioTemporal,
|
|
257
|
+
bulto,
|
|
258
|
+
cantidad
|
|
259
|
+
});
|
|
232
260
|
if (!grouped && forzarAgrupamientoDeLinea) {
|
|
233
261
|
this.dataToInsert.lines.push({
|
|
234
262
|
id_envio: idEnvioTemporal,
|
|
235
263
|
bulto
|
|
236
264
|
});
|
|
237
265
|
}
|
|
238
|
-
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
239
|
-
this.dataToInsert.details.push({
|
|
240
|
-
id_envio: idEnvioTemporal,
|
|
241
|
-
bulto,
|
|
242
|
-
cantidad
|
|
243
|
-
});
|
|
244
266
|
if (!grouped && !forzarAgrupamientoDeLinea) {
|
|
267
|
+
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
245
268
|
arrayFake.forEach(() => {
|
|
246
269
|
this.dataToInsert.lines.push({
|
|
247
270
|
id_envio: idEnvioTemporal,
|
package/index.ts
CHANGED
|
@@ -141,13 +141,7 @@ export class IntegrationManager {
|
|
|
141
141
|
|
|
142
142
|
const idEnvioTemporal = await this.insertTempShipment({
|
|
143
143
|
order: parsedOrder,
|
|
144
|
-
agencyId
|
|
145
|
-
defaultAgencyId: agencyId,
|
|
146
|
-
userId: idUsuario,
|
|
147
|
-
integrationId: this.integrationType,
|
|
148
|
-
tempShipmentData: parsedOrder,
|
|
149
|
-
sellerAddress
|
|
150
|
-
}),
|
|
144
|
+
agencyId,
|
|
151
145
|
warehouseId,
|
|
152
146
|
sellerAddress,
|
|
153
147
|
idUsuario,
|
|
@@ -164,7 +158,7 @@ export class IntegrationManager {
|
|
|
164
158
|
idEnvioTemporal
|
|
165
159
|
});
|
|
166
160
|
|
|
167
|
-
return Object.assign(parsedOrder, { idEnvioTemporal });
|
|
161
|
+
return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
|
|
168
162
|
},
|
|
169
163
|
regularExecutionTime: 8000, // ms
|
|
170
164
|
initialBatchQuantity: 5 // de cinco en cinco
|
|
@@ -173,7 +167,10 @@ export class IntegrationManager {
|
|
|
173
167
|
const successfullShipments = insertOrdersResult
|
|
174
168
|
.filter(Boolean)
|
|
175
169
|
.filter((each) => each.status === 'fulfilled')
|
|
176
|
-
.map((each) => each.value)
|
|
170
|
+
.map((each) => each.value) as (ModifiedOrder & {
|
|
171
|
+
idEnvioTemporal: number;
|
|
172
|
+
agencyId: number;
|
|
173
|
+
})[];
|
|
177
174
|
|
|
178
175
|
await this.insertQuantityRelatedLines({
|
|
179
176
|
orders: successfullShipments,
|
|
@@ -188,19 +185,50 @@ export class IntegrationManager {
|
|
|
188
185
|
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
189
186
|
)
|
|
190
187
|
});
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
188
|
+
|
|
189
|
+
// modificamos la agencia, cuando se tenga que hacer
|
|
190
|
+
await Promise.allSettled(
|
|
191
|
+
successfullShipments.map(async (order) => {
|
|
192
|
+
const shipmentDetails = this.dataToInsert.details.filter(
|
|
193
|
+
({ id_envio }) => {
|
|
194
|
+
return id_envio === order.idEnvioTemporal;
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const newAgencyId = await this.getAgencyIdForTempShipment({
|
|
199
|
+
defaultAgencyId: agencyId,
|
|
200
|
+
userId: idUsuario,
|
|
201
|
+
integrationId: this.integrationType,
|
|
202
|
+
tempShipmentData: order,
|
|
203
|
+
sellerAddress,
|
|
204
|
+
shipmentDetails
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (newAgencyId !== order.agencyId) {
|
|
208
|
+
await integrationsService.updateTempShimpment({
|
|
209
|
+
id_envio: order.idEnvioTemporal,
|
|
210
|
+
id_usuario: idUsuario,
|
|
211
|
+
id_agencia: newAgencyId
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
})
|
|
202
215
|
);
|
|
203
216
|
|
|
217
|
+
await Promise.allSettled([
|
|
218
|
+
integrationsService.insertTempShipmentMultipleLines(
|
|
219
|
+
this.dataToInsert.lines
|
|
220
|
+
),
|
|
221
|
+
integrationsService.insertTempShipmentMultipleDetails(
|
|
222
|
+
this.dataToInsert.details
|
|
223
|
+
),
|
|
224
|
+
integrationsService.insertTempShipmentMultipleContents(
|
|
225
|
+
this.dataToInsert.contents
|
|
226
|
+
),
|
|
227
|
+
integrationsService.insertTempShipmentMultipleExternals(
|
|
228
|
+
this.dataToInsert.externals
|
|
229
|
+
)
|
|
230
|
+
]);
|
|
231
|
+
|
|
204
232
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
205
233
|
}
|
|
206
234
|
|
|
@@ -346,6 +374,13 @@ export class IntegrationManager {
|
|
|
346
374
|
forzarAgrupamientoDeLinea: boolean;
|
|
347
375
|
};
|
|
348
376
|
|
|
377
|
+
/*
|
|
378
|
+
basicamente la logica es:
|
|
379
|
+
1 - si esta agrupado, crea una linea por cada pedido
|
|
380
|
+
2 - si "forzarAgrupamientoDeLinea" es true, se crea una linea por cada linea
|
|
381
|
+
3- si NO esta agrupado y "forzarAgrupamientoDeLinea" NO es true, se crea una linea por cada unidad de cada linea
|
|
382
|
+
*/
|
|
383
|
+
|
|
349
384
|
const grouped = Number(group?.grouped === 1);
|
|
350
385
|
|
|
351
386
|
const createBultoFromLine = async ({
|
|
@@ -395,6 +430,12 @@ export class IntegrationManager {
|
|
|
395
430
|
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } =
|
|
396
431
|
each;
|
|
397
432
|
try {
|
|
433
|
+
this.dataToInsert.details.push({
|
|
434
|
+
id_envio: idEnvioTemporal,
|
|
435
|
+
bulto,
|
|
436
|
+
cantidad
|
|
437
|
+
});
|
|
438
|
+
|
|
398
439
|
if (!grouped && forzarAgrupamientoDeLinea) {
|
|
399
440
|
this.dataToInsert.lines.push({
|
|
400
441
|
id_envio: idEnvioTemporal,
|
|
@@ -402,15 +443,9 @@ export class IntegrationManager {
|
|
|
402
443
|
});
|
|
403
444
|
}
|
|
404
445
|
|
|
405
|
-
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
406
|
-
|
|
407
|
-
this.dataToInsert.details.push({
|
|
408
|
-
id_envio: idEnvioTemporal,
|
|
409
|
-
bulto,
|
|
410
|
-
cantidad
|
|
411
|
-
});
|
|
412
|
-
|
|
413
446
|
if (!grouped && !forzarAgrupamientoDeLinea) {
|
|
447
|
+
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
448
|
+
|
|
414
449
|
arrayFake.forEach(() => {
|
|
415
450
|
this.dataToInsert.lines.push({
|
|
416
451
|
id_envio: idEnvioTemporal,
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -222,6 +222,15 @@ export type IntegrationsService = {
|
|
|
222
222
|
insertTempShipmentMultipleExternals: (
|
|
223
223
|
externals: DataToInsert['externals']
|
|
224
224
|
) => number | false;
|
|
225
|
+
updateTempShimpment: ({
|
|
226
|
+
id_envio,
|
|
227
|
+
id_usuario,
|
|
228
|
+
id_agencia
|
|
229
|
+
}: {
|
|
230
|
+
id_envio: number;
|
|
231
|
+
id_usuario: number;
|
|
232
|
+
id_agencia: number;
|
|
233
|
+
}) => Promise<boolean>;
|
|
225
234
|
};
|
|
226
235
|
|
|
227
236
|
export type SellerAddress = {
|
|
@@ -340,6 +349,7 @@ export type GetAgencyIdForTempShipment = (params: {
|
|
|
340
349
|
integrationId: number;
|
|
341
350
|
tempShipmentData: ModifiedOrder;
|
|
342
351
|
sellerAddress: SellerAddress;
|
|
352
|
+
shipmentDetails: InsertContentShipmentDetail[];
|
|
343
353
|
}) => Promise<number>;
|
|
344
354
|
|
|
345
355
|
export type ExecutionManager = {
|