cardus 0.0.25 → 0.0.27

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
@@ -17,13 +17,14 @@ const moment_1 = __importDefault(require("moment"));
17
17
  const insertTempShipment_1 = require("./insertTempShipment");
18
18
  class IntegrationManager {
19
19
  constructor(params) {
20
- this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, group }) {
20
+ this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, group, isPriority }) {
21
21
  const idEnvioTemporal = yield this.insertTempShipment({
22
22
  order,
23
23
  agencyId,
24
24
  warehouseId,
25
25
  sellerAddress,
26
- idUsuario
26
+ idUsuario,
27
+ isPriority,
27
28
  });
28
29
  if (!idEnvioTemporal)
29
30
  throw new Error('Temp shipments could not be created');
@@ -37,7 +38,7 @@ class IntegrationManager {
37
38
  yield this.insertTempShipmentLines({ idEnvioTemporal, group });
38
39
  return Object.assign(order, { idEnvioTemporal });
39
40
  });
40
- this.insertTempShipment = (_b) => __awaiter(this, [_b], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario }) {
41
+ this.insertTempShipment = (_b) => __awaiter(this, [_b], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, isPriority }) {
41
42
  const tempShipmentData = yield (0, insertTempShipment_1.cookTempShipment)({
42
43
  order,
43
44
  shipmentType: this.shipmentType,
@@ -46,7 +47,8 @@ class IntegrationManager {
46
47
  sellerAddress,
47
48
  idUsuario,
48
49
  findNextPickupDate: this.findNextPickupDate,
49
- countriesService: this.services.countriesService
50
+ countriesService: this.services.countriesService,
51
+ isPriority
50
52
  });
51
53
  return yield this.services.integrationsService.insertTempShipment(tempShipmentData);
52
54
  });
@@ -85,16 +87,18 @@ class IntegrationManager {
85
87
  addressesService: params.addressesService,
86
88
  countriesService: params.countriesService,
87
89
  configurationService: params.configurationService,
88
- usersService: params.usersService
90
+ usersService: params.usersService,
91
+ customizationService: params.customizationService,
89
92
  };
90
93
  this.shipmentType = params.shipmentType;
91
94
  this.type = params.type;
92
95
  this.executionManager = params.executionManager;
93
96
  this.findNextPickupDate = params.findNextPickupDate;
94
- this.getAgencyIdFromTempShipment = params.getAgencyIdFromTempShipment;
97
+ this.getAgencyIdForTempShipment = params.getAgencyIdForTempShipment;
95
98
  }
96
99
  insertTempShipments(_a) {
97
100
  return __awaiter(this, arguments, void 0, function* ({ payload: { idUsuario, agencyId, addressId, warehouseId, group }, fetchAllOrders, crearBulto, modificarOrdenOriginal }) {
101
+ const user = yield this.services.usersService.obtenerUsuarioId(idUsuario);
98
102
  const estaAgrupado = Number(group === null || group === void 0 ? void 0 : group.grouped) === 1;
99
103
  const { integrationsService, addressesService } = this.services;
100
104
  // esto hay que pasarlo ya en los parametros
@@ -107,7 +111,19 @@ class IntegrationManager {
107
111
  orders: allOrders,
108
112
  type: this.type
109
113
  });
110
- const insertOrdersResult = yield new this.executionManager({
114
+ const isPriorityByDefault = () => __awaiter(this, void 0, void 0, function* () {
115
+ const usuariosGeneiPriority = yield this.services.customizationService.getUsersWithSection(8);
116
+ const esPotencialmentePriority = usuariosGeneiPriority.some((seccion) => seccion.id_usuario === user.id_usuario ||
117
+ seccion.tipo_cliente === user.tipo_cliente ||
118
+ seccion.id_comercial === user.id_comercial);
119
+ if (!esPotencialmentePriority) {
120
+ return 0;
121
+ }
122
+ else {
123
+ return +user.priority; // 1 o 0
124
+ }
125
+ });
126
+ const insertOrdersResult = new this.executionManager({
111
127
  arrayParams: allOrders,
112
128
  executable: (order) => __awaiter(this, void 0, void 0, function* () {
113
129
  const parsedOrder = yield modificarOrdenOriginal({
@@ -118,15 +134,17 @@ class IntegrationManager {
118
134
  throw new Error('Envio Duplicado');
119
135
  return this.insertOrder({
120
136
  order: parsedOrder,
121
- agencyId: yield this.getAgencyIdFromTempShipment({
137
+ agencyId: yield this.getAgencyIdForTempShipment({
122
138
  defaultAgencyId: agencyId,
139
+ userId: idUsuario,
123
140
  integrationId: this.shipmentType,
124
- tempShipmentData: parsedOrder
141
+ tempShipmentData: parsedOrder,
125
142
  }),
126
143
  warehouseId,
127
144
  sellerAddress,
128
145
  idUsuario,
129
- group
146
+ group,
147
+ isPriority: yield isPriorityByDefault(),
130
148
  });
131
149
  }),
132
150
  regularExecutionTime: 100, // ms
@@ -143,14 +161,15 @@ class IntegrationManager {
143
161
  estaAgrupado
144
162
  });
145
163
  yield this.insertUserDefaultConfigurationContent({
146
- idUsuario,
164
+ user,
147
165
  tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
148
166
  });
149
167
  return filteredOrders;
150
168
  });
151
169
  }
152
170
  insertUserDefaultConfigurationContent(_a) {
153
- return __awaiter(this, arguments, void 0, function* ({ idUsuario, tempShimpmentIds }) {
171
+ return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
172
+ const idUsuario = user.id_usuario;
154
173
  const { usersService, configurationService, integrationsService } = this.services;
155
174
  const insert = (data, tempShimpmentId) => __awaiter(this, void 0, void 0, function* () {
156
175
  return Promise.allSettled(data.map((tempContent) => __awaiter(this, void 0, void 0, function* () {
@@ -165,7 +184,6 @@ class IntegrationManager {
165
184
  yield insert(userSavedData, order);
166
185
  }
167
186
  else {
168
- const user = yield usersService.obtenerUsuarioId(idUsuario);
169
187
  const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
170
188
  yield insert(userFakeData, order);
171
189
  }
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.cookTempShipment = void 0;
16
16
  const moment_1 = __importDefault(require("moment"));
17
- const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ order, shipmentType, agencyId, warehouseId, sellerAddress, idUsuario, findNextPickupDate, countriesService }) {
17
+ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ order, shipmentType, agencyId, warehouseId, sellerAddress, idUsuario, findNextPickupDate, countriesService, isPriority }) {
18
18
  let zonaLLegada = {};
19
19
  if (order.codigoPaisLLegada)
20
20
  zonaLLegada = yield countriesService.getCountryFromCountryCode(order.codigoPaisLLegada);
@@ -116,7 +116,7 @@ const cookTempShipment = (_a) => __awaiter(void 0, [_a], void 0, function* ({ or
116
116
  const dataInsert = (yield setters.reduce((acc, curr) => __awaiter(void 0, void 0, void 0, function* () {
117
117
  const accumulated = yield acc;
118
118
  const stepResult = yield curr(Object.assign(Object.assign({}, order), accumulated));
119
- return Object.assign(Object.assign({}, accumulated), stepResult);
119
+ return Object.assign(Object.assign(Object.assign({}, accumulated), stepResult), { priority: isPriority });
120
120
  }), {}));
121
121
  return dataInsert;
122
122
  });
package/index.ts CHANGED
@@ -20,7 +20,9 @@ import {
20
20
  ModifiedOrder,
21
21
  ShipmentType,
22
22
  UserDefaultConfigurationContent,
23
- GetAgencyIdForTempShipment
23
+ GetAgencyIdForTempShipment,
24
+ IsPriority,
25
+ CustomizationService
24
26
  } from './types';
25
27
 
26
28
  interface Services {
@@ -29,6 +31,7 @@ interface Services {
29
31
  countriesService: CountriesService;
30
32
  configurationService: ConfigurationService;
31
33
  usersService: UsersService;
34
+ customizationService: CustomizationService;
32
35
  }
33
36
 
34
37
  export class IntegrationManager {
@@ -37,7 +40,7 @@ export class IntegrationManager {
37
40
  executionManager: ExecutionManager;
38
41
  findNextPickupDate: FindNextPickupDate;
39
42
  shipmentType: ShipmentType;
40
- getAgencyIdFromTempShipment: GetAgencyIdForTempShipment;
43
+ getAgencyIdForTempShipment: GetAgencyIdForTempShipment;
41
44
 
42
45
  constructor(params: {
43
46
  integrationsService: IntegrationsService;
@@ -45,25 +48,27 @@ export class IntegrationManager {
45
48
  countriesService: CountriesService;
46
49
  configurationService: ConfigurationService;
47
50
  usersService: UsersService;
51
+ customizationService: CustomizationService;
48
52
  type: Type;
49
53
  shipmentType: ShipmentType;
50
54
  executionManager: ExecutionManager;
51
55
  findNextPickupDate: FindNextPickupDate;
52
- getAgencyIdFromTempShipment: GetAgencyIdForTempShipment;
56
+ getAgencyIdForTempShipment: GetAgencyIdForTempShipment;
53
57
  }) {
54
58
  this.services = {
55
59
  integrationsService: params.integrationsService,
56
60
  addressesService: params.addressesService,
57
61
  countriesService: params.countriesService,
58
62
  configurationService: params.configurationService,
59
- usersService: params.usersService
63
+ usersService: params.usersService,
64
+ customizationService: params.customizationService,
60
65
  };
61
66
 
62
67
  this.shipmentType = params.shipmentType;
63
68
  this.type = params.type;
64
69
  this.executionManager = params.executionManager;
65
70
  this.findNextPickupDate = params.findNextPickupDate;
66
- this.getAgencyIdFromTempShipment = params.getAgencyIdFromTempShipment;
71
+ this.getAgencyIdForTempShipment = params.getAgencyIdForTempShipment;
67
72
  }
68
73
 
69
74
  async insertTempShipments({
@@ -72,6 +77,7 @@ export class IntegrationManager {
72
77
  crearBulto,
73
78
  modificarOrdenOriginal
74
79
  }: InsertParams) {
80
+ const user = await this.services.usersService.obtenerUsuarioId(idUsuario);
75
81
  const estaAgrupado = Number(group?.grouped) === 1;
76
82
  const { integrationsService, addressesService } = this.services;
77
83
  // esto hay que pasarlo ya en los parametros
@@ -88,31 +94,48 @@ export class IntegrationManager {
88
94
  type: this.type
89
95
  });
90
96
 
91
- const insertOrdersResult = await new this.executionManager({
97
+ const isPriorityByDefault = async () => {
98
+ const usuariosGeneiPriority = await this.services.customizationService.getUsersWithSection(8);
99
+ const esPotencialmentePriority = usuariosGeneiPriority.some(
100
+ (seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any; }) =>
101
+ seccion.id_usuario === user.id_usuario ||
102
+ seccion.tipo_cliente === user.tipo_cliente ||
103
+ seccion.id_comercial === user.id_comercial
104
+ );
105
+
106
+ if (!esPotencialmentePriority) {
107
+ return 0;
108
+ } else {
109
+ return +user.priority; // 1 o 0
110
+ }
111
+ };
112
+
113
+ const insertOrdersResult = new this.executionManager({
92
114
  arrayParams: allOrders,
93
115
  executable: async (order: OriginalOrder) => {
94
116
  const parsedOrder = await modificarOrdenOriginal({
95
117
  originalOrder: order
96
118
  });
97
119
 
98
- const duplicatedTempShipment =
99
- await integrationsService.checkDuplicateTempShipment(
100
- parsedOrder.codigoEnvioExterno,
101
- idUsuario
102
- );
120
+ const duplicatedTempShipment = await integrationsService.checkDuplicateTempShipment(
121
+ parsedOrder.codigoEnvioExterno,
122
+ idUsuario
123
+ );
103
124
  if (duplicatedTempShipment) throw new Error('Envio Duplicado');
104
125
 
105
126
  return this.insertOrder({
106
127
  order: parsedOrder,
107
- agencyId: await this.getAgencyIdFromTempShipment({
128
+ agencyId: await this.getAgencyIdForTempShipment({
108
129
  defaultAgencyId: agencyId,
130
+ userId: idUsuario,
109
131
  integrationId: this.shipmentType,
110
- tempShipmentData: parsedOrder
132
+ tempShipmentData: parsedOrder,
111
133
  }),
112
134
  warehouseId,
113
135
  sellerAddress,
114
136
  idUsuario,
115
- group
137
+ group,
138
+ isPriority: await isPriorityByDefault(),
116
139
  });
117
140
  },
118
141
  regularExecutionTime: 100, // ms
@@ -132,7 +155,7 @@ export class IntegrationManager {
132
155
  });
133
156
 
134
157
  await this.insertUserDefaultConfigurationContent({
135
- idUsuario,
158
+ user,
136
159
  tempShimpmentIds: successfullShipments.map(
137
160
  (successfullShipment) => successfullShipment.idEnvioTemporal
138
161
  )
@@ -142,12 +165,13 @@ export class IntegrationManager {
142
165
  }
143
166
 
144
167
  async insertUserDefaultConfigurationContent({
145
- idUsuario,
168
+ user,
146
169
  tempShimpmentIds
147
170
  }: {
148
- idUsuario: number;
171
+ user: { id_usuario: number, dni: string };
149
172
  tempShimpmentIds: number[];
150
173
  }) {
174
+ const idUsuario = user.id_usuario
151
175
  const { usersService, configurationService, integrationsService } =
152
176
  this.services;
153
177
 
@@ -178,7 +202,6 @@ export class IntegrationManager {
178
202
  if (userSavedData.length > 0) {
179
203
  await insert(userSavedData, order);
180
204
  } else {
181
- const user = await usersService.obtenerUsuarioId(idUsuario);
182
205
  const userFakeData =
183
206
  configurationService.getFakeDefaultProformaConfiguration(
184
207
  idUsuario,
@@ -198,7 +221,8 @@ export class IntegrationManager {
198
221
  warehouseId,
199
222
  sellerAddress,
200
223
  idUsuario,
201
- group
224
+ group,
225
+ isPriority
202
226
  }: {
203
227
  order: ModifiedOrder;
204
228
  agencyId: number;
@@ -206,13 +230,15 @@ export class IntegrationManager {
206
230
  sellerAddress: SellerAddress;
207
231
  idUsuario: number;
208
232
  group: Group;
233
+ isPriority: IsPriority
209
234
  }): Promise<ModifiedOrderExtended> => {
210
235
  const idEnvioTemporal = await this.insertTempShipment({
211
236
  order,
212
237
  agencyId,
213
238
  warehouseId,
214
239
  sellerAddress,
215
- idUsuario
240
+ idUsuario,
241
+ isPriority,
216
242
  });
217
243
 
218
244
  if (!idEnvioTemporal)
@@ -234,13 +260,15 @@ export class IntegrationManager {
234
260
  agencyId,
235
261
  warehouseId,
236
262
  sellerAddress,
237
- idUsuario
263
+ idUsuario,
264
+ isPriority
238
265
  }: {
239
266
  order: ModifiedOrder;
240
267
  agencyId: number;
241
268
  warehouseId: number;
242
269
  sellerAddress: SellerAddress;
243
270
  idUsuario: number;
271
+ isPriority: IsPriority
244
272
  }) => {
245
273
  const tempShipmentData = await cookTempShipment({
246
274
  order,
@@ -250,7 +278,8 @@ export class IntegrationManager {
250
278
  sellerAddress,
251
279
  idUsuario,
252
280
  findNextPickupDate: this.findNextPickupDate,
253
- countriesService: this.services.countriesService
281
+ countriesService: this.services.countriesService,
282
+ isPriority
254
283
  });
255
284
 
256
285
  return await this.services.integrationsService.insertTempShipment(
@@ -5,7 +5,8 @@ import {
5
5
  ModifiedOrder,
6
6
  CountriesService,
7
7
  FindNextPickupDate,
8
- SellerAddress
8
+ SellerAddress,
9
+ IsPriority
9
10
  } from 'types';
10
11
 
11
12
  type ZonaLLegada = { nombre_pais: string; id_pais: number };
@@ -18,7 +19,8 @@ export const cookTempShipment = async ({
18
19
  sellerAddress,
19
20
  idUsuario,
20
21
  findNextPickupDate,
21
- countriesService
22
+ countriesService,
23
+ isPriority
22
24
  }: {
23
25
  order: ModifiedOrder;
24
26
  shipmentType: ShipmentType;
@@ -28,6 +30,7 @@ export const cookTempShipment = async ({
28
30
  idUsuario: number;
29
31
  findNextPickupDate: FindNextPickupDate;
30
32
  countriesService: CountriesService;
33
+ isPriority: IsPriority
31
34
  }): Promise<Shipment> => {
32
35
  let zonaLLegada = {};
33
36
  if (order.codigoPaisLLegada)
@@ -173,7 +176,8 @@ export const cookTempShipment = async ({
173
176
 
174
177
  return {
175
178
  ...accumulated,
176
- ...stepResult
179
+ ...stepResult,
180
+ priority: isPriority
177
181
  };
178
182
 
179
183
  }, {})) as Shipment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardus",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "an integration manager",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/types/index.ts CHANGED
@@ -32,6 +32,7 @@ export type Shipment = {
32
32
  tipo_envio: Type;
33
33
  codigo_envio_externo: string;
34
34
  id_almacen: number;
35
+ priority: 0 | 1;
35
36
  };
36
37
 
37
38
  const shipmentTypes = {
@@ -94,6 +95,7 @@ export type ModifiedOrder = {
94
95
  marketplaceId?: string | null;
95
96
  idDocumentoHolded?: string;
96
97
  tipoDocumentoHolded?: string;
98
+ isPriority: 0 | 1;
97
99
  };
98
100
 
99
101
  export interface ModifiedOrderExtended extends ModifiedOrder {
@@ -241,6 +243,10 @@ export type UserDefaultConfigurationContent = {
241
243
 
242
244
  type User = {
243
245
  dni: string;
246
+ id_usuario: number;
247
+ tipo_cliente: number;
248
+ id_comercial: number;
249
+ priority: number;
244
250
  };
245
251
 
246
252
  export type ConfigurationService = {
@@ -255,10 +261,16 @@ export type ConfigurationService = {
255
261
  ) => UserDefaultConfigurationContent[];
256
262
  };
257
263
 
264
+ export type IsPriority = number
265
+
258
266
  export type UsersService = {
259
267
  obtenerUsuarioId: (id_usuario: number) => Promise<User>;
260
268
  };
261
269
 
270
+ export type CustomizationService = {
271
+ getUsersWithSection: (seccion: number) => Promise<User[]>;
272
+ }
273
+
262
274
  export type FindNextPickupDate = (params: {
263
275
  fecha?: string;
264
276
  cp_salida: string;
@@ -283,6 +295,7 @@ type ExecutionManagerUploadReturn = {
283
295
 
284
296
  export type GetAgencyIdForTempShipment = (params: {
285
297
  defaultAgencyId: number;
298
+ userId: number;
286
299
  integrationId: number;
287
300
  tempShipmentData: ModifiedOrder;
288
301
  }) => Promise<number>;