cardus 0.0.100 → 0.0.101
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 +78 -73
- package/index.ts +120 -111
- package/insertTempShipment/index.ts +3 -12
- package/package.json +1 -1
- package/types/index.ts +30 -11
package/dist/index.js
CHANGED
|
@@ -17,20 +17,6 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
17
17
|
const insertTempShipment_1 = require("./insertTempShipment");
|
|
18
18
|
class IntegrationManager {
|
|
19
19
|
constructor(params) {
|
|
20
|
-
this.insertTempShipment = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, isPriority }) {
|
|
21
|
-
const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
|
|
22
|
-
order,
|
|
23
|
-
shipmentType: this.shipmentType,
|
|
24
|
-
agencyId,
|
|
25
|
-
warehouseId,
|
|
26
|
-
sellerAddress,
|
|
27
|
-
idUsuario,
|
|
28
|
-
findNextPickupDate: this.findNextPickupDate,
|
|
29
|
-
countriesService: this.services.countriesService,
|
|
30
|
-
isPriority
|
|
31
|
-
});
|
|
32
|
-
return yield this.services.integrationsService.insertTempShipment(tempShipmentData, false);
|
|
33
|
-
});
|
|
34
20
|
this.insertExternalShipment = ({ idUsuario, order, idEnvioTemporal }) => {
|
|
35
21
|
this.dataToInsert.externals.push({
|
|
36
22
|
id_envio_temporal_usuario: idEnvioTemporal,
|
|
@@ -48,16 +34,19 @@ class IntegrationManager {
|
|
|
48
34
|
});
|
|
49
35
|
};
|
|
50
36
|
this.insertTempShipmentGroupLine = ({ idEnvioTemporal, group }) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
}
|
|
59
48
|
}
|
|
60
|
-
|
|
49
|
+
]);
|
|
61
50
|
};
|
|
62
51
|
this.services = {
|
|
63
52
|
integrationsService: params.integrationsService,
|
|
@@ -70,7 +59,7 @@ class IntegrationManager {
|
|
|
70
59
|
warehouseService: params.warehouseService
|
|
71
60
|
};
|
|
72
61
|
this.dataToInsert = {
|
|
73
|
-
lines:
|
|
62
|
+
lines: new Map(),
|
|
74
63
|
contents: [],
|
|
75
64
|
details: [],
|
|
76
65
|
externals: [],
|
|
@@ -81,7 +70,7 @@ class IntegrationManager {
|
|
|
81
70
|
this.type = params.type;
|
|
82
71
|
this.executionManager = params.executionManager;
|
|
83
72
|
this.findNextPickupDate = params.findNextPickupDate;
|
|
84
|
-
this.
|
|
73
|
+
this.getModifiedOrderBasedOnRules = params.getModifiedOrderBasedOnRules;
|
|
85
74
|
}
|
|
86
75
|
insertTempShipments(_a) {
|
|
87
76
|
return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group, sequentialInsertion = false }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
|
|
@@ -92,6 +81,11 @@ class IntegrationManager {
|
|
|
92
81
|
? yield addressesService.getWarehouseAddress(idUsuario)
|
|
93
82
|
: yield addressesService.getAddress(addressId, idUsuario);
|
|
94
83
|
const country = yield this.services.countriesService.getCountry(sellerAddress.id_pais);
|
|
84
|
+
const userIntegrationConfiguration = yield integrationsService.getDefaultIntegrationsData({
|
|
85
|
+
id_usuario: idUsuario,
|
|
86
|
+
id_integracion: this.integrationType
|
|
87
|
+
});
|
|
88
|
+
const shouldFindWarehouseSkus = !!(userIntegrationConfiguration === null || userIntegrationConfiguration === void 0 ? void 0 : userIntegrationConfiguration.sku_almacen);
|
|
95
89
|
const allOrders = yield fetchAllOrders();
|
|
96
90
|
const filteredOrders = yield integrationsService.filterExternalDuplicatedOrders({
|
|
97
91
|
id_usuario: idUsuario,
|
|
@@ -121,17 +115,61 @@ class IntegrationManager {
|
|
|
121
115
|
if (parsedOrder.direccionSalidaId) {
|
|
122
116
|
direccionSalida = yield addressesService.getAddress(parsedOrder.direccionSalidaId, idUsuario);
|
|
123
117
|
}
|
|
124
|
-
const
|
|
118
|
+
const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
|
|
125
119
|
order: parsedOrder,
|
|
120
|
+
shipmentType: this.shipmentType,
|
|
126
121
|
agencyId,
|
|
127
122
|
warehouseId,
|
|
128
|
-
sellerAddress
|
|
123
|
+
sellerAddress,
|
|
129
124
|
idUsuario,
|
|
125
|
+
findNextPickupDate: this.findNextPickupDate,
|
|
126
|
+
countriesService: this.services.countriesService,
|
|
130
127
|
isPriority: isPriorityByDefault
|
|
131
128
|
});
|
|
129
|
+
const idEnvioTemporal = yield this.services.integrationsService.insertTempShipment(tempShipmentData, false);
|
|
132
130
|
if (!idEnvioTemporal) {
|
|
133
131
|
throw new Error('Temp shipments could not be created');
|
|
134
132
|
}
|
|
133
|
+
yield this.insertQuantityRelatedLines({
|
|
134
|
+
orders: [Object.assign(Object.assign({}, parsedOrder), { idEnvioTemporal })],
|
|
135
|
+
idUsuario,
|
|
136
|
+
crearBulto,
|
|
137
|
+
group,
|
|
138
|
+
warehouseId,
|
|
139
|
+
shouldFindWarehouseSkus
|
|
140
|
+
});
|
|
141
|
+
const shipmentDetails = this.dataToInsert.details.filter(({ id_envio }) => {
|
|
142
|
+
return id_envio === order.idEnvioTemporal;
|
|
143
|
+
});
|
|
144
|
+
const { partialTempShipmentModified, packagesModified } = yield this.getModifiedOrderBasedOnRules({
|
|
145
|
+
defaultAgencyId: agencyId,
|
|
146
|
+
userId: idUsuario,
|
|
147
|
+
integrationId: this.integrationType,
|
|
148
|
+
parsedOrder,
|
|
149
|
+
sellerAddress,
|
|
150
|
+
shipmentDetails,
|
|
151
|
+
tempShipmentData,
|
|
152
|
+
packages: this.dataToInsert.lines.get(idEnvioTemporal) || []
|
|
153
|
+
});
|
|
154
|
+
const isTempShipmentModified = !!partialTempShipmentModified &&
|
|
155
|
+
Object.keys(partialTempShipmentModified).length > 0;
|
|
156
|
+
const arePackagesModified = !!packagesModified && packagesModified.length > 0;
|
|
157
|
+
const shouldAbortCreation = isTempShipmentModified &&
|
|
158
|
+
partialTempShipmentModified.abort_creation === true;
|
|
159
|
+
if (shouldAbortCreation) {
|
|
160
|
+
yield integrationsService.deleteTempShipment({
|
|
161
|
+
id_envio: idEnvioTemporal,
|
|
162
|
+
id_usuario: idUsuario
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (isTempShipmentModified) {
|
|
167
|
+
delete partialTempShipmentModified.abort_creation; // por si acaso
|
|
168
|
+
yield integrationsService.updateTempShimpment(Object.assign({ id_envio: idEnvioTemporal }, tempShipmentData));
|
|
169
|
+
}
|
|
170
|
+
if (arePackagesModified) {
|
|
171
|
+
this.dataToInsert.lines.set(idEnvioTemporal, packagesModified);
|
|
172
|
+
}
|
|
135
173
|
this.insertExternalShipment({
|
|
136
174
|
idUsuario,
|
|
137
175
|
order: parsedOrder,
|
|
@@ -142,55 +180,22 @@ class IntegrationManager {
|
|
|
142
180
|
regularExecutionTime: 8000, // ms
|
|
143
181
|
initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
|
|
144
182
|
}).upload();
|
|
145
|
-
const successfullShipments = insertOrdersResult
|
|
146
|
-
.filter(Boolean)
|
|
147
|
-
.filter((each) => each.status === 'fulfilled')
|
|
148
|
-
.map((each) => each.value);
|
|
149
|
-
const userIntegrationConfiguration = yield integrationsService.getDefaultIntegrationsData({
|
|
150
|
-
id_usuario: idUsuario,
|
|
151
|
-
id_integracion: this.integrationType
|
|
152
|
-
});
|
|
153
|
-
const shouldFindWarehouseSkus = !!(userIntegrationConfiguration === null || userIntegrationConfiguration === void 0 ? void 0 : userIntegrationConfiguration.sku_almacen);
|
|
154
|
-
yield this.insertQuantityRelatedLines({
|
|
155
|
-
orders: successfullShipments,
|
|
156
|
-
idUsuario,
|
|
157
|
-
crearBulto,
|
|
158
|
-
group,
|
|
159
|
-
warehouseId,
|
|
160
|
-
shouldFindWarehouseSkus
|
|
161
|
-
});
|
|
162
183
|
yield this.insertUserDefaultConfigurationContent({
|
|
163
184
|
user,
|
|
164
185
|
countryName: country.nombre_pais_en
|
|
165
186
|
});
|
|
166
|
-
|
|
167
|
-
yield Promise.allSettled(successfullShipments.map((order) => __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
const shipmentDetails = this.dataToInsert.details.filter(({ id_envio }) => {
|
|
169
|
-
return id_envio === order.idEnvioTemporal;
|
|
170
|
-
});
|
|
171
|
-
const newAgencyId = yield this.getAgencyIdForTempShipment({
|
|
172
|
-
defaultAgencyId: agencyId,
|
|
173
|
-
userId: idUsuario,
|
|
174
|
-
integrationId: this.integrationType,
|
|
175
|
-
tempShipmentData: order,
|
|
176
|
-
sellerAddress,
|
|
177
|
-
shipmentDetails
|
|
178
|
-
});
|
|
179
|
-
if (newAgencyId !== order.agencyId) {
|
|
180
|
-
yield integrationsService.updateTempShimpment({
|
|
181
|
-
id_envio: order.idEnvioTemporal,
|
|
182
|
-
id_usuario: idUsuario,
|
|
183
|
-
id_agencia: newAgencyId
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
})));
|
|
187
|
+
const arrayPackages = Array.from(Object.values(this.dataToInsert.lines)).flat();
|
|
187
188
|
yield Promise.allSettled([
|
|
188
|
-
integrationsService.insertTempShipmentMultipleLines(
|
|
189
|
+
integrationsService.insertTempShipmentMultipleLines(arrayPackages),
|
|
189
190
|
integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details),
|
|
190
191
|
integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents),
|
|
191
192
|
integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals),
|
|
192
193
|
integrationsService.insertTempShipmentMultipleJsonQuantityReferences(this.dataToInsert.jsonQuantityReferences)
|
|
193
194
|
]);
|
|
195
|
+
const successfullShipments = insertOrdersResult
|
|
196
|
+
.filter(Boolean)
|
|
197
|
+
.filter((each) => each.status === 'fulfilled')
|
|
198
|
+
.map((each) => each.value);
|
|
194
199
|
return {
|
|
195
200
|
filteredOrders,
|
|
196
201
|
insertedTempShipments: successfullShipments,
|
|
@@ -372,8 +377,9 @@ class IntegrationManager {
|
|
|
372
377
|
}
|
|
373
378
|
else {
|
|
374
379
|
// 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)
|
|
380
|
+
const tempShipmentLines = this.dataToInsert.lines.get(idEnvioTemporal) || [];
|
|
375
381
|
if (forzarAgrupamientoDeLinea) {
|
|
376
|
-
|
|
382
|
+
tempShipmentLines.push({
|
|
377
383
|
id_envio: idEnvioTemporal,
|
|
378
384
|
bulto
|
|
379
385
|
});
|
|
@@ -382,12 +388,11 @@ class IntegrationManager {
|
|
|
382
388
|
else {
|
|
383
389
|
// 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-)
|
|
384
390
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
385
|
-
arrayFake.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
});
|
|
391
|
+
const linesToAdd = arrayFake.map(() => ({
|
|
392
|
+
id_envio: idEnvioTemporal,
|
|
393
|
+
bulto
|
|
394
|
+
}));
|
|
395
|
+
tempShipmentLines.push(...linesToAdd);
|
|
391
396
|
}
|
|
392
397
|
}
|
|
393
398
|
// para cuando el usuario quiere mapear su sku con la referencia que tenga en almacen
|
package/index.ts
CHANGED
|
@@ -23,14 +23,15 @@ import {
|
|
|
23
23
|
ShipmentType,
|
|
24
24
|
IntegrationType,
|
|
25
25
|
UserDefaultConfigurationContent,
|
|
26
|
-
|
|
26
|
+
GetModifiedOrderBasedOnRules,
|
|
27
27
|
IsPriority,
|
|
28
28
|
CustomizationService,
|
|
29
29
|
InsertContentShipmentLine,
|
|
30
30
|
Bulto,
|
|
31
31
|
DataToInsert,
|
|
32
32
|
BultoYCantidad,
|
|
33
|
-
JsonReferenciasCantidades
|
|
33
|
+
JsonReferenciasCantidades,
|
|
34
|
+
Shipment
|
|
34
35
|
} from './types';
|
|
35
36
|
|
|
36
37
|
interface Services {
|
|
@@ -51,7 +52,7 @@ export class IntegrationManager {
|
|
|
51
52
|
findNextPickupDate: FindNextPickupDate;
|
|
52
53
|
integrationType: IntegrationType;
|
|
53
54
|
shipmentType: ShipmentType;
|
|
54
|
-
|
|
55
|
+
getModifiedOrderBasedOnRules: GetModifiedOrderBasedOnRules;
|
|
55
56
|
|
|
56
57
|
dataToInsert: DataToInsert;
|
|
57
58
|
|
|
@@ -69,7 +70,7 @@ export class IntegrationManager {
|
|
|
69
70
|
shipmentType: ShipmentType;
|
|
70
71
|
executionManager: ExecutionManager;
|
|
71
72
|
findNextPickupDate: FindNextPickupDate;
|
|
72
|
-
|
|
73
|
+
getModifiedOrderBasedOnRules: GetModifiedOrderBasedOnRules;
|
|
73
74
|
}) {
|
|
74
75
|
this.services = {
|
|
75
76
|
integrationsService: params.integrationsService,
|
|
@@ -83,7 +84,7 @@ export class IntegrationManager {
|
|
|
83
84
|
};
|
|
84
85
|
|
|
85
86
|
this.dataToInsert = {
|
|
86
|
-
lines:
|
|
87
|
+
lines: new Map(),
|
|
87
88
|
contents: [],
|
|
88
89
|
details: [],
|
|
89
90
|
externals: [],
|
|
@@ -95,7 +96,7 @@ export class IntegrationManager {
|
|
|
95
96
|
this.type = params.type;
|
|
96
97
|
this.executionManager = params.executionManager;
|
|
97
98
|
this.findNextPickupDate = params.findNextPickupDate;
|
|
98
|
-
this.
|
|
99
|
+
this.getModifiedOrderBasedOnRules = params.getModifiedOrderBasedOnRules;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
async insertTempShipments({
|
|
@@ -118,10 +119,19 @@ export class IntegrationManager {
|
|
|
118
119
|
warehouseId > 0
|
|
119
120
|
? await addressesService.getWarehouseAddress(idUsuario)
|
|
120
121
|
: await addressesService.getAddress(addressId, idUsuario);
|
|
122
|
+
|
|
121
123
|
const country = await this.services.countriesService.getCountry(
|
|
122
124
|
sellerAddress.id_pais
|
|
123
125
|
);
|
|
124
126
|
|
|
127
|
+
const userIntegrationConfiguration =
|
|
128
|
+
await integrationsService.getDefaultIntegrationsData({
|
|
129
|
+
id_usuario: idUsuario,
|
|
130
|
+
id_integracion: this.integrationType
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const shouldFindWarehouseSkus = !!userIntegrationConfiguration?.sku_almacen;
|
|
134
|
+
|
|
125
135
|
const allOrders = await fetchAllOrders();
|
|
126
136
|
const filteredOrders =
|
|
127
137
|
await integrationsService.filterExternalDuplicatedOrders({
|
|
@@ -167,19 +177,87 @@ export class IntegrationManager {
|
|
|
167
177
|
);
|
|
168
178
|
}
|
|
169
179
|
|
|
170
|
-
const
|
|
180
|
+
const tempShipmentData = await cookTempShipment({
|
|
171
181
|
order: parsedOrder,
|
|
182
|
+
shipmentType: this.shipmentType,
|
|
172
183
|
agencyId,
|
|
173
184
|
warehouseId,
|
|
174
|
-
sellerAddress
|
|
185
|
+
sellerAddress,
|
|
175
186
|
idUsuario,
|
|
187
|
+
findNextPickupDate: this.findNextPickupDate,
|
|
188
|
+
countriesService: this.services.countriesService,
|
|
176
189
|
isPriority: isPriorityByDefault
|
|
177
190
|
});
|
|
178
191
|
|
|
192
|
+
const idEnvioTemporal =
|
|
193
|
+
await this.services.integrationsService.insertTempShipment(
|
|
194
|
+
tempShipmentData,
|
|
195
|
+
false
|
|
196
|
+
);
|
|
197
|
+
|
|
179
198
|
if (!idEnvioTemporal) {
|
|
180
199
|
throw new Error('Temp shipments could not be created');
|
|
181
200
|
}
|
|
182
201
|
|
|
202
|
+
await this.insertQuantityRelatedLines({
|
|
203
|
+
orders: [{ ...parsedOrder, idEnvioTemporal }],
|
|
204
|
+
idUsuario,
|
|
205
|
+
crearBulto,
|
|
206
|
+
group,
|
|
207
|
+
warehouseId,
|
|
208
|
+
shouldFindWarehouseSkus
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const shipmentDetails = this.dataToInsert.details.filter(
|
|
212
|
+
({ id_envio }) => {
|
|
213
|
+
return id_envio === order.idEnvioTemporal;
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const { partialTempShipmentModified, packagesModified } =
|
|
218
|
+
await this.getModifiedOrderBasedOnRules({
|
|
219
|
+
defaultAgencyId: agencyId,
|
|
220
|
+
userId: idUsuario,
|
|
221
|
+
integrationId: this.integrationType,
|
|
222
|
+
parsedOrder,
|
|
223
|
+
sellerAddress,
|
|
224
|
+
shipmentDetails,
|
|
225
|
+
tempShipmentData,
|
|
226
|
+
packages: this.dataToInsert.lines.get(idEnvioTemporal) || []
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const isTempShipmentModified =
|
|
230
|
+
!!partialTempShipmentModified &&
|
|
231
|
+
Object.keys(partialTempShipmentModified).length > 0;
|
|
232
|
+
const arePackagesModified =
|
|
233
|
+
!!packagesModified && packagesModified.length > 0;
|
|
234
|
+
|
|
235
|
+
const shouldAbortCreation =
|
|
236
|
+
isTempShipmentModified &&
|
|
237
|
+
partialTempShipmentModified.abort_creation === true;
|
|
238
|
+
|
|
239
|
+
if (shouldAbortCreation) {
|
|
240
|
+
await integrationsService.deleteTempShipment({
|
|
241
|
+
id_envio: idEnvioTemporal,
|
|
242
|
+
id_usuario: idUsuario
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (isTempShipmentModified) {
|
|
249
|
+
delete partialTempShipmentModified.abort_creation; // por si acaso
|
|
250
|
+
|
|
251
|
+
await integrationsService.updateTempShimpment({
|
|
252
|
+
id_envio: idEnvioTemporal,
|
|
253
|
+
...tempShipmentData
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (arePackagesModified) {
|
|
258
|
+
this.dataToInsert.lines.set(idEnvioTemporal, packagesModified);
|
|
259
|
+
}
|
|
260
|
+
|
|
183
261
|
this.insertExternalShipment({
|
|
184
262
|
idUsuario,
|
|
185
263
|
order: parsedOrder,
|
|
@@ -192,67 +270,17 @@ export class IntegrationManager {
|
|
|
192
270
|
initialBatchQuantity: sequentialInsertion ? 1 : 5 // si la insercion no es secuencial, de cinco en cinco
|
|
193
271
|
}).upload();
|
|
194
272
|
|
|
195
|
-
const successfullShipments = insertOrdersResult
|
|
196
|
-
.filter(Boolean)
|
|
197
|
-
.filter((each) => each.status === 'fulfilled')
|
|
198
|
-
.map((each) => each.value) as (ModifiedOrder & {
|
|
199
|
-
idEnvioTemporal: number;
|
|
200
|
-
agencyId: number;
|
|
201
|
-
})[];
|
|
202
|
-
|
|
203
|
-
const userIntegrationConfiguration =
|
|
204
|
-
await integrationsService.getDefaultIntegrationsData({
|
|
205
|
-
id_usuario: idUsuario,
|
|
206
|
-
id_integracion: this.integrationType
|
|
207
|
-
});
|
|
208
|
-
const shouldFindWarehouseSkus = !!userIntegrationConfiguration?.sku_almacen;
|
|
209
|
-
|
|
210
|
-
await this.insertQuantityRelatedLines({
|
|
211
|
-
orders: successfullShipments,
|
|
212
|
-
idUsuario,
|
|
213
|
-
crearBulto,
|
|
214
|
-
group,
|
|
215
|
-
warehouseId,
|
|
216
|
-
shouldFindWarehouseSkus
|
|
217
|
-
});
|
|
218
|
-
|
|
219
273
|
await this.insertUserDefaultConfigurationContent({
|
|
220
274
|
user,
|
|
221
275
|
countryName: country.nombre_pais_en
|
|
222
276
|
});
|
|
223
277
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const shipmentDetails = this.dataToInsert.details.filter(
|
|
228
|
-
({ id_envio }) => {
|
|
229
|
-
return id_envio === order.idEnvioTemporal;
|
|
230
|
-
}
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
const newAgencyId = await this.getAgencyIdForTempShipment({
|
|
234
|
-
defaultAgencyId: agencyId,
|
|
235
|
-
userId: idUsuario,
|
|
236
|
-
integrationId: this.integrationType,
|
|
237
|
-
tempShipmentData: order,
|
|
238
|
-
sellerAddress,
|
|
239
|
-
shipmentDetails
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
if (newAgencyId !== order.agencyId) {
|
|
243
|
-
await integrationsService.updateTempShimpment({
|
|
244
|
-
id_envio: order.idEnvioTemporal,
|
|
245
|
-
id_usuario: idUsuario,
|
|
246
|
-
id_agencia: newAgencyId
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
})
|
|
250
|
-
);
|
|
278
|
+
const arrayPackages: InsertContentShipmentLine[] = Array.from(
|
|
279
|
+
Object.values(this.dataToInsert.lines)
|
|
280
|
+
).flat();
|
|
251
281
|
|
|
252
282
|
await Promise.allSettled([
|
|
253
|
-
integrationsService.insertTempShipmentMultipleLines(
|
|
254
|
-
this.dataToInsert.lines
|
|
255
|
-
),
|
|
283
|
+
integrationsService.insertTempShipmentMultipleLines(arrayPackages),
|
|
256
284
|
integrationsService.insertTempShipmentMultipleDetails(
|
|
257
285
|
this.dataToInsert.details
|
|
258
286
|
),
|
|
@@ -267,6 +295,14 @@ export class IntegrationManager {
|
|
|
267
295
|
)
|
|
268
296
|
]);
|
|
269
297
|
|
|
298
|
+
const successfullShipments = insertOrdersResult
|
|
299
|
+
.filter(Boolean)
|
|
300
|
+
.filter((each) => each.status === 'fulfilled')
|
|
301
|
+
.map((each) => each.value) as (ModifiedOrder & {
|
|
302
|
+
idEnvioTemporal: number;
|
|
303
|
+
agencyId: number;
|
|
304
|
+
})[];
|
|
305
|
+
|
|
270
306
|
return {
|
|
271
307
|
filteredOrders,
|
|
272
308
|
insertedTempShipments: successfullShipments,
|
|
@@ -369,39 +405,6 @@ export class IntegrationManager {
|
|
|
369
405
|
}
|
|
370
406
|
}
|
|
371
407
|
|
|
372
|
-
insertTempShipment = async ({
|
|
373
|
-
order,
|
|
374
|
-
agencyId,
|
|
375
|
-
warehouseId,
|
|
376
|
-
sellerAddress,
|
|
377
|
-
idUsuario,
|
|
378
|
-
isPriority
|
|
379
|
-
}: {
|
|
380
|
-
order: ModifiedOrder;
|
|
381
|
-
agencyId: number;
|
|
382
|
-
warehouseId: number;
|
|
383
|
-
sellerAddress: SellerAddress;
|
|
384
|
-
idUsuario: number;
|
|
385
|
-
isPriority: IsPriority;
|
|
386
|
-
}) => {
|
|
387
|
-
const tempShipmentData = await cookTempShipment({
|
|
388
|
-
order,
|
|
389
|
-
shipmentType: this.shipmentType,
|
|
390
|
-
agencyId,
|
|
391
|
-
warehouseId,
|
|
392
|
-
sellerAddress,
|
|
393
|
-
idUsuario,
|
|
394
|
-
findNextPickupDate: this.findNextPickupDate,
|
|
395
|
-
countriesService: this.services.countriesService,
|
|
396
|
-
isPriority
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
return await this.services.integrationsService.insertTempShipment(
|
|
400
|
-
tempShipmentData,
|
|
401
|
-
false
|
|
402
|
-
);
|
|
403
|
-
};
|
|
404
|
-
|
|
405
408
|
insertExternalShipment = ({
|
|
406
409
|
idUsuario,
|
|
407
410
|
order,
|
|
@@ -434,16 +437,19 @@ export class IntegrationManager {
|
|
|
434
437
|
idEnvioTemporal: number;
|
|
435
438
|
group: Group;
|
|
436
439
|
}) => {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
440
|
+
// 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-
|
|
441
|
+
this.dataToInsert.lines.set(idEnvioTemporal, [
|
|
442
|
+
{
|
|
443
|
+
id_envio: idEnvioTemporal,
|
|
444
|
+
bulto: {
|
|
445
|
+
peso: group.weight,
|
|
446
|
+
alto: group.height,
|
|
447
|
+
ancho: group.width,
|
|
448
|
+
largo: group.length,
|
|
449
|
+
sku_producto: ''
|
|
450
|
+
}
|
|
445
451
|
}
|
|
446
|
-
|
|
452
|
+
]);
|
|
447
453
|
};
|
|
448
454
|
|
|
449
455
|
async createJsonQuantityReferencesFromLines({
|
|
@@ -609,22 +615,25 @@ export class IntegrationManager {
|
|
|
609
615
|
// si no agrupamos, cogemos el peso y dimensiones del peso mismo
|
|
610
616
|
} else {
|
|
611
617
|
// 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)
|
|
618
|
+
const tempShipmentLines =
|
|
619
|
+
this.dataToInsert.lines.get(idEnvioTemporal) || [];
|
|
620
|
+
|
|
612
621
|
if (forzarAgrupamientoDeLinea) {
|
|
613
|
-
|
|
622
|
+
tempShipmentLines.push({
|
|
614
623
|
id_envio: idEnvioTemporal,
|
|
615
624
|
bulto
|
|
616
625
|
});
|
|
617
626
|
// y esto para todo el resto de usuarios
|
|
618
627
|
} else {
|
|
619
628
|
// 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-)
|
|
629
|
+
|
|
620
630
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
631
|
+
const linesToAdd = arrayFake.map(() => ({
|
|
632
|
+
id_envio: idEnvioTemporal,
|
|
633
|
+
bulto
|
|
634
|
+
}));
|
|
621
635
|
|
|
622
|
-
|
|
623
|
-
this.dataToInsert.lines.push({
|
|
624
|
-
id_envio: idEnvioTemporal,
|
|
625
|
-
bulto
|
|
626
|
-
});
|
|
627
|
-
});
|
|
636
|
+
tempShipmentLines.push(...linesToAdd);
|
|
628
637
|
}
|
|
629
638
|
}
|
|
630
639
|
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
CountriesService,
|
|
7
7
|
FindNextPickupDate,
|
|
8
8
|
SellerAddress,
|
|
9
|
-
IsPriority
|
|
9
|
+
IsPriority,
|
|
10
|
+
TempShipmentDataForCooking
|
|
10
11
|
} from 'types';
|
|
11
12
|
|
|
12
13
|
type ZonaLLegada = { nombre_pais: string; id_pais: number };
|
|
@@ -21,17 +22,7 @@ export const cookTempShipment = async ({
|
|
|
21
22
|
findNextPickupDate,
|
|
22
23
|
countriesService,
|
|
23
24
|
isPriority
|
|
24
|
-
}: {
|
|
25
|
-
order: ModifiedOrder;
|
|
26
|
-
shipmentType: ShipmentType;
|
|
27
|
-
agencyId: number;
|
|
28
|
-
warehouseId: number;
|
|
29
|
-
sellerAddress: SellerAddress;
|
|
30
|
-
idUsuario: number;
|
|
31
|
-
findNextPickupDate: FindNextPickupDate;
|
|
32
|
-
countriesService: CountriesService;
|
|
33
|
-
isPriority: IsPriority;
|
|
34
|
-
}): Promise<Shipment> => {
|
|
25
|
+
}: TempShipmentDataForCooking): Promise<Shipment> => {
|
|
35
26
|
let zonaLLegada = {};
|
|
36
27
|
if (order.codigoPaisLLegada)
|
|
37
28
|
zonaLLegada = await countriesService.getCountryFromCountryCode(
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -233,7 +233,7 @@ export type IntegrationsService = {
|
|
|
233
233
|
) => Promise<number | false>;
|
|
234
234
|
|
|
235
235
|
insertTempShipmentMultipleLines: (
|
|
236
|
-
lines:
|
|
236
|
+
lines: InsertContentShipmentLine[]
|
|
237
237
|
) => Promise<number | false>;
|
|
238
238
|
|
|
239
239
|
insertTempShipmentMultipleDetails: (
|
|
@@ -254,12 +254,7 @@ export type IntegrationsService = {
|
|
|
254
254
|
id_envio,
|
|
255
255
|
id_usuario,
|
|
256
256
|
id_agencia
|
|
257
|
-
}: {
|
|
258
|
-
id_envio: number;
|
|
259
|
-
id_usuario: number;
|
|
260
|
-
id_agencia: number;
|
|
261
|
-
}) => Promise<boolean>;
|
|
262
|
-
|
|
257
|
+
}: Partial<Shipment & { id_envio: number }>) => Promise<boolean>;
|
|
263
258
|
getDefaultIntegrationsData: ({
|
|
264
259
|
id_usuario,
|
|
265
260
|
id_integracion
|
|
@@ -270,6 +265,13 @@ export type IntegrationsService = {
|
|
|
270
265
|
sku_almacen: 0 | 1;
|
|
271
266
|
dimensiones_medidas_configuradas: 0 | 1;
|
|
272
267
|
}>;
|
|
268
|
+
deleteTempShipment: ({
|
|
269
|
+
id_envio,
|
|
270
|
+
id_usuario
|
|
271
|
+
}: {
|
|
272
|
+
id_envio: number;
|
|
273
|
+
id_usuario: number;
|
|
274
|
+
}) => Promise<number | false>;
|
|
273
275
|
};
|
|
274
276
|
|
|
275
277
|
export type LlmAPIService = {
|
|
@@ -407,14 +409,19 @@ type ExecutionManagerUploadReturn = {
|
|
|
407
409
|
value: any;
|
|
408
410
|
};
|
|
409
411
|
|
|
410
|
-
export type
|
|
412
|
+
export type GetModifiedOrderBasedOnRules = (params: {
|
|
411
413
|
defaultAgencyId: number;
|
|
412
414
|
userId: number;
|
|
413
415
|
integrationId: number;
|
|
414
|
-
|
|
416
|
+
parsedOrder: ModifiedOrder;
|
|
415
417
|
sellerAddress: SellerAddress;
|
|
416
418
|
shipmentDetails: InsertContentShipmentDetail[];
|
|
417
|
-
|
|
419
|
+
tempShipmentData: Shipment;
|
|
420
|
+
packages: InsertContentShipmentLine[];
|
|
421
|
+
}) => Promise<{
|
|
422
|
+
partialTempShipmentModified: Partial<Shipment & { abort_creation?: boolean }>;
|
|
423
|
+
packagesModified: InsertContentShipmentLine[];
|
|
424
|
+
}>;
|
|
418
425
|
|
|
419
426
|
export type ExecutionManager = {
|
|
420
427
|
upload(): ExecutionManagerUploadReturn[];
|
|
@@ -422,7 +429,7 @@ export type ExecutionManager = {
|
|
|
422
429
|
};
|
|
423
430
|
|
|
424
431
|
export type DataToInsert = {
|
|
425
|
-
lines: InsertContentShipmentLine[]
|
|
432
|
+
lines: Map<number, InsertContentShipmentLine[]>;
|
|
426
433
|
contents: InsertContentShipmentData[];
|
|
427
434
|
details: InsertContentShipmentDetail[];
|
|
428
435
|
externals: InsertContentShipmentExternal[];
|
|
@@ -437,6 +444,18 @@ export type InsertContentShipmentLine = {
|
|
|
437
444
|
>;
|
|
438
445
|
};
|
|
439
446
|
|
|
447
|
+
export type TempShipmentDataForCooking = {
|
|
448
|
+
order: ModifiedOrder;
|
|
449
|
+
shipmentType: ShipmentType;
|
|
450
|
+
agencyId: number;
|
|
451
|
+
warehouseId: number;
|
|
452
|
+
sellerAddress: SellerAddress;
|
|
453
|
+
idUsuario: number;
|
|
454
|
+
findNextPickupDate: FindNextPickupDate;
|
|
455
|
+
countriesService: CountriesService;
|
|
456
|
+
isPriority: IsPriority;
|
|
457
|
+
};
|
|
458
|
+
|
|
440
459
|
type InsertContentShipmentData = UserDefaultConfigurationContent & {
|
|
441
460
|
id_envio: number;
|
|
442
461
|
};
|