cardus 0.0.54 → 0.0.56

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 CHANGED
@@ -117,13 +117,7 @@ class IntegrationManager {
117
117
  });
118
118
  const idEnvioTemporal = yield this.insertTempShipment({
119
119
  order: parsedOrder,
120
- agencyId: yield this.getAgencyIdForTempShipment({
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,6 +131,7 @@ class IntegrationManager {
137
131
  order: parsedOrder,
138
132
  idEnvioTemporal
139
133
  });
134
+ return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
140
135
  }),
141
136
  regularExecutionTime: 8000, // ms
142
137
  initialBatchQuantity: 5 // de cinco en cinco
@@ -155,10 +150,31 @@ class IntegrationManager {
155
150
  user,
156
151
  tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
157
152
  });
158
- yield integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines);
159
- yield integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details);
160
- yield integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents);
161
- yield integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals);
153
+ // modificamos la agencia, cuando se tenga que hacer
154
+ successfullShipments.forEach((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
+ integrationsService.updateTempShimpment({
168
+ id_envio: order.idEnvioTemporal,
169
+ id_usuario: idUsuario,
170
+ id_agencia: newAgencyId
171
+ });
172
+ }
173
+ }));
174
+ integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines);
175
+ integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details);
176
+ integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents);
177
+ integrationsService.insertTempShipmentMultipleExternals(this.dataToInsert.externals);
162
178
  return { filteredOrders, insertedTempShipments: successfullShipments };
163
179
  });
164
180
  }
@@ -192,6 +208,12 @@ class IntegrationManager {
192
208
  }
193
209
  insertQuantityRelatedLines(_a) {
194
210
  return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group }) {
211
+ /*
212
+ basicamente la logica es:
213
+ 1 - si esta agrupado, crea una linea por cada pedido
214
+ 2 - si "forzarAgrupamientoDeLinea" es true, se crea una linea por cada linea
215
+ 3- si NO esta agrupado y "forzarAgrupamientoDeLinea" NO es true, se crea una linea por cada unidad de cada linea
216
+ */
195
217
  const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
196
218
  const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
197
219
  const result = yield crearBulto({
@@ -228,19 +250,19 @@ class IntegrationManager {
228
250
  return;
229
251
  const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } = each;
230
252
  try {
253
+ this.dataToInsert.details.push({
254
+ id_envio: idEnvioTemporal,
255
+ bulto,
256
+ cantidad
257
+ });
231
258
  if (!grouped && forzarAgrupamientoDeLinea) {
232
259
  this.dataToInsert.lines.push({
233
260
  id_envio: idEnvioTemporal,
234
261
  bulto
235
262
  });
236
263
  }
237
- const arrayFake = Array.from({ length: Number(cantidad) });
238
- this.dataToInsert.details.push({
239
- id_envio: idEnvioTemporal,
240
- bulto,
241
- cantidad
242
- });
243
264
  if (!grouped && !forzarAgrupamientoDeLinea) {
265
+ const arrayFake = Array.from({ length: Number(cantidad) });
244
266
  arrayFake.forEach(() => {
245
267
  this.dataToInsert.lines.push({
246
268
  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: await this.getAgencyIdForTempShipment({
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,
@@ -163,6 +157,8 @@ export class IntegrationManager {
163
157
  order: parsedOrder,
164
158
  idEnvioTemporal
165
159
  });
160
+
161
+ return Object.assign(parsedOrder, { idEnvioTemporal, agencyId });
166
162
  },
167
163
  regularExecutionTime: 8000, // ms
168
164
  initialBatchQuantity: 5 // de cinco en cinco
@@ -171,7 +167,10 @@ export class IntegrationManager {
171
167
  const successfullShipments = insertOrdersResult
172
168
  .filter(Boolean)
173
169
  .filter((each) => each.status === 'fulfilled')
174
- .map((each) => each.value);
170
+ .map((each) => each.value) as (ModifiedOrder & {
171
+ idEnvioTemporal: number;
172
+ agencyId: number;
173
+ })[];
175
174
 
176
175
  await this.insertQuantityRelatedLines({
177
176
  orders: successfullShipments,
@@ -186,16 +185,44 @@ export class IntegrationManager {
186
185
  (successfullShipment) => successfullShipment.idEnvioTemporal
187
186
  )
188
187
  });
189
- await integrationsService.insertTempShipmentMultipleLines(
188
+
189
+ // modificamos la agencia, cuando se tenga que hacer
190
+
191
+ successfullShipments.forEach(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
+ integrationsService.updateTempShimpment({
209
+ id_envio: order.idEnvioTemporal,
210
+ id_usuario: idUsuario,
211
+ id_agencia: newAgencyId
212
+ });
213
+ }
214
+ });
215
+
216
+ integrationsService.insertTempShipmentMultipleLines(
190
217
  this.dataToInsert.lines
191
218
  );
192
- await integrationsService.insertTempShipmentMultipleDetails(
219
+ integrationsService.insertTempShipmentMultipleDetails(
193
220
  this.dataToInsert.details
194
221
  );
195
- await integrationsService.insertTempShipmentMultipleContents(
222
+ integrationsService.insertTempShipmentMultipleContents(
196
223
  this.dataToInsert.contents
197
224
  );
198
- await integrationsService.insertTempShipmentMultipleExternals(
225
+ integrationsService.insertTempShipmentMultipleExternals(
199
226
  this.dataToInsert.externals
200
227
  );
201
228
 
@@ -344,6 +371,13 @@ export class IntegrationManager {
344
371
  forzarAgrupamientoDeLinea: boolean;
345
372
  };
346
373
 
374
+ /*
375
+ basicamente la logica es:
376
+ 1 - si esta agrupado, crea una linea por cada pedido
377
+ 2 - si "forzarAgrupamientoDeLinea" es true, se crea una linea por cada linea
378
+ 3- si NO esta agrupado y "forzarAgrupamientoDeLinea" NO es true, se crea una linea por cada unidad de cada linea
379
+ */
380
+
347
381
  const grouped = Number(group?.grouped === 1);
348
382
 
349
383
  const createBultoFromLine = async ({
@@ -393,6 +427,12 @@ export class IntegrationManager {
393
427
  const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } =
394
428
  each;
395
429
  try {
430
+ this.dataToInsert.details.push({
431
+ id_envio: idEnvioTemporal,
432
+ bulto,
433
+ cantidad
434
+ });
435
+
396
436
  if (!grouped && forzarAgrupamientoDeLinea) {
397
437
  this.dataToInsert.lines.push({
398
438
  id_envio: idEnvioTemporal,
@@ -400,15 +440,9 @@ export class IntegrationManager {
400
440
  });
401
441
  }
402
442
 
403
- const arrayFake = Array.from({ length: Number(cantidad) });
404
-
405
- this.dataToInsert.details.push({
406
- id_envio: idEnvioTemporal,
407
- bulto,
408
- cantidad
409
- });
410
-
411
443
  if (!grouped && !forzarAgrupamientoDeLinea) {
444
+ const arrayFake = Array.from({ length: Number(cantidad) });
445
+
412
446
  arrayFake.forEach(() => {
413
447
  this.dataToInsert.lines.push({
414
448
  id_envio: idEnvioTemporal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
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 = {