cardus 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/index.ts +62 -66
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -38,67 +38,63 @@ export class IntegrationManager {
38
38
  crearBulto,
39
39
  modificarOrdenOriginal,
40
40
  }: InsertParams) {
41
- try {
42
- const estaAgrupado = Number(group?.grouped) === 1;
43
- const { integrationsService, addressesService } = this.services;
44
- // esto hay que pasarlo ya en los parametros
45
- const sellerAddress =
46
- warehouseId > 0
47
- ? await addressesService.getWarehouseAddress(idUsuario)
48
- : await addressesService.getAddress(addressId, idUsuario);
49
-
50
- const allShopifyOrders = await fetchAllOrders();
51
-
52
- const filteredOrders = await integrationsService.filterExternalDuplicatedOrders({
53
- idUsuario,
54
- orders: allShopifyOrders,
55
- type: this.type,
56
- });
41
+ const estaAgrupado = Number(group?.grouped) === 1;
42
+ const { integrationsService, addressesService } = this.services;
43
+ // esto hay que pasarlo ya en los parametros
44
+ const sellerAddress =
45
+ warehouseId > 0
46
+ ? await addressesService.getWarehouseAddress(idUsuario)
47
+ : await addressesService.getAddress(addressId, idUsuario);
57
48
 
58
- const insertOrdersResult = await new this.executionManager({
59
- arrayParams: allShopifyOrders,
60
- executable: async (order: OriginalOrder) => {
61
- const parsedOrder = modificarOrdenOriginal({ originalOrder: order })
62
- const duplicatedTempShipment = await integrationsService.checkDuplicateTempShipment(
63
- parsedOrder.codigoEnvioExterno,
64
- idUsuario,
65
- );
66
- if (duplicatedTempShipment) return;
49
+ const allShopifyOrders = await fetchAllOrders();
67
50
 
68
- return this.insertOrder({
69
- order: parsedOrder,
70
- agencyId,
71
- warehouseId,
72
- sellerAddress,
73
- idUsuario,
74
- group,
75
- });
76
- },
77
- regularExecutionTime: 100, // ms
78
- initialBatchQuantity: 1, // de uno en uno
79
- }).upload();
80
-
81
- const successfullShipments = insertOrdersResult
82
- .filter(Boolean)
83
- .filter((each) => each.status === "fulfilled")
84
- .map((each) => each.value)
85
-
86
- await this.insertQuantityRelatedLines({
87
- orders: successfullShipments,
88
- idUsuario,
89
- crearBulto,
90
- estaAgrupado,
91
- });
51
+ const filteredOrders = await integrationsService.filterExternalDuplicatedOrders({
52
+ idUsuario,
53
+ orders: allShopifyOrders,
54
+ type: this.type,
55
+ });
92
56
 
93
- return filteredOrders;
94
- } catch (e) {
95
- console.log(e)
96
- }
57
+ const insertOrdersResult = await new this.executionManager({
58
+ arrayParams: allShopifyOrders,
59
+ executable: async (order: OriginalOrder) => {
60
+ const parsedOrder = modificarOrdenOriginal({ originalOrder: order })
61
+ const duplicatedTempShipment = await integrationsService.checkDuplicateTempShipment(
62
+ parsedOrder.codigoEnvioExterno,
63
+ idUsuario,
64
+ );
65
+ if (duplicatedTempShipment) return;
66
+
67
+ return this.insertOrder({
68
+ order: parsedOrder,
69
+ agencyId,
70
+ warehouseId,
71
+ sellerAddress,
72
+ idUsuario,
73
+ group,
74
+ });
75
+ },
76
+ regularExecutionTime: 100, // ms
77
+ initialBatchQuantity: 1, // de uno en uno
78
+ }).upload();
79
+
80
+ const successfullShipments = insertOrdersResult
81
+ .filter(Boolean)
82
+ .filter((each) => each.status === "fulfilled")
83
+ .map((each) => each.value)
84
+
85
+ await this.insertQuantityRelatedLines({
86
+ orders: successfullShipments,
87
+ idUsuario,
88
+ crearBulto,
89
+ estaAgrupado,
90
+ });
91
+
92
+ return filteredOrders;
97
93
  }
98
94
 
99
95
  insertOrder = async (
100
96
  { order, agencyId, warehouseId, sellerAddress, idUsuario, group }:
101
- { order: ModifiedOrder, agencyId: number, warehouseId: number, sellerAddress: SellerAddress, idUsuario: number, group: Group }): Promise<ModifiedOrderExtended> => {
97
+ { order: ModifiedOrder, agencyId: number, warehouseId: number, sellerAddress: SellerAddress, idUsuario: number, group: Group }): Promise<ModifiedOrderExtended> => {
102
98
 
103
99
  const idEnvioTemporal = await this.insertTempShipment({
104
100
  order,
@@ -139,7 +135,7 @@ export class IntegrationManager {
139
135
  return await this.services.integrationsService.insertTempShipment(tempShipmentData);
140
136
  };
141
137
 
142
- insertExternalShipment = async ({ idUsuario, order, idEnvioTemporal }:
138
+ insertExternalShipment = async ({ idUsuario, order, idEnvioTemporal }:
143
139
  { idUsuario: number, order: ModifiedOrder, idEnvioTemporal: number }
144
140
  ): Promise<number | false> => {
145
141
  const idEnvioExterno = await this.services.integrationsService.insertExternalShipment({
@@ -155,22 +151,22 @@ export class IntegrationManager {
155
151
  };
156
152
 
157
153
  insertTempShipmentLines = async ({ idEnvioTemporal, group }: {
158
- idEnvioTemporal: number, group: Group
154
+ idEnvioTemporal: number, group: Group
159
155
  }) => {
160
156
  const grouped = group.grouped === 1 || group.grouped === '1';
161
157
  if (grouped)
162
- await this.services.integrationsService.insertTempShipmentLines({
163
- id_envio: idEnvioTemporal,
164
- bulto: {
165
- peso: group.weight,
166
- alto: group.height,
167
- ancho: group.width,
168
- largo: group.length,
169
- },
170
- });
158
+ await this.services.integrationsService.insertTempShipmentLines({
159
+ id_envio: idEnvioTemporal,
160
+ bulto: {
161
+ peso: group.weight,
162
+ alto: group.height,
163
+ ancho: group.width,
164
+ largo: group.length,
165
+ },
166
+ });
171
167
  };
172
168
 
173
- async insertQuantityRelatedLines({ orders, idUsuario, crearBulto, estaAgrupado }:
169
+ async insertQuantityRelatedLines({ orders, idUsuario, crearBulto, estaAgrupado }:
174
170
  {
175
171
  orders: ModifiedOrderExtended[], idUsuario: number, crearBulto: CrearBulto, estaAgrupado: boolean
176
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "an integration manager",
5
5
  "main": "index.js",
6
6
  "module": "dist/index.mjs",