cardus 0.0.55 → 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,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,31 @@ class IntegrationManager {
156
150
  user,
157
151
  tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
158
152
  });
159
- yield integrationsService.insertTempShipmentMultipleLines(this.dataToInsert.lines);
160
- yield integrationsService.insertTempShipmentMultipleDetails(this.dataToInsert.details);
161
- yield integrationsService.insertTempShipmentMultipleContents(this.dataToInsert.contents);
162
- 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);
163
178
  return { filteredOrders, insertedTempShipments: successfullShipments };
164
179
  });
165
180
  }
@@ -193,6 +208,12 @@ class IntegrationManager {
193
208
  }
194
209
  insertQuantityRelatedLines(_a) {
195
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
+ */
196
217
  const grouped = Number((group === null || group === void 0 ? void 0 : group.grouped) === 1);
197
218
  const createBultoFromLine = (_b) => __awaiter(this, [_b], void 0, function* ({ line, idEnvioTemporal }) {
198
219
  const result = yield crearBulto({
@@ -229,19 +250,19 @@ class IntegrationManager {
229
250
  return;
230
251
  const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } = each;
231
252
  try {
253
+ this.dataToInsert.details.push({
254
+ id_envio: idEnvioTemporal,
255
+ bulto,
256
+ cantidad
257
+ });
232
258
  if (!grouped && forzarAgrupamientoDeLinea) {
233
259
  this.dataToInsert.lines.push({
234
260
  id_envio: idEnvioTemporal,
235
261
  bulto
236
262
  });
237
263
  }
238
- const arrayFake = Array.from({ length: Number(cantidad) });
239
- this.dataToInsert.details.push({
240
- id_envio: idEnvioTemporal,
241
- bulto,
242
- cantidad
243
- });
244
264
  if (!grouped && !forzarAgrupamientoDeLinea) {
265
+ const arrayFake = Array.from({ length: Number(cantidad) });
245
266
  arrayFake.forEach(() => {
246
267
  this.dataToInsert.lines.push({
247
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,
@@ -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,16 +185,44 @@ export class IntegrationManager {
188
185
  (successfullShipment) => successfullShipment.idEnvioTemporal
189
186
  )
190
187
  });
191
- 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(
192
217
  this.dataToInsert.lines
193
218
  );
194
- await integrationsService.insertTempShipmentMultipleDetails(
219
+ integrationsService.insertTempShipmentMultipleDetails(
195
220
  this.dataToInsert.details
196
221
  );
197
- await integrationsService.insertTempShipmentMultipleContents(
222
+ integrationsService.insertTempShipmentMultipleContents(
198
223
  this.dataToInsert.contents
199
224
  );
200
- await integrationsService.insertTempShipmentMultipleExternals(
225
+ integrationsService.insertTempShipmentMultipleExternals(
201
226
  this.dataToInsert.externals
202
227
  );
203
228
 
@@ -346,6 +371,13 @@ export class IntegrationManager {
346
371
  forzarAgrupamientoDeLinea: boolean;
347
372
  };
348
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
+
349
381
  const grouped = Number(group?.grouped === 1);
350
382
 
351
383
  const createBultoFromLine = async ({
@@ -395,6 +427,12 @@ export class IntegrationManager {
395
427
  const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } =
396
428
  each;
397
429
  try {
430
+ this.dataToInsert.details.push({
431
+ id_envio: idEnvioTemporal,
432
+ bulto,
433
+ cantidad
434
+ });
435
+
398
436
  if (!grouped && forzarAgrupamientoDeLinea) {
399
437
  this.dataToInsert.lines.push({
400
438
  id_envio: idEnvioTemporal,
@@ -402,15 +440,9 @@ export class IntegrationManager {
402
440
  });
403
441
  }
404
442
 
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
443
  if (!grouped && !forzarAgrupamientoDeLinea) {
444
+ const arrayFake = Array.from({ length: Number(cantidad) });
445
+
414
446
  arrayFake.forEach(() => {
415
447
  this.dataToInsert.lines.push({
416
448
  id_envio: idEnvioTemporal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.55",
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 = {