cardus 0.0.26 → 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 +28 -11
- package/dist/insertTempShipment/index.js +2 -2
- package/index.ts +46 -18
- package/insertTempShipment/index.ts +7 -3
- package/package.json +1 -1
- package/types/index.ts +12 -0
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,7 +87,8 @@ 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;
|
|
@@ -95,6 +98,7 @@ class IntegrationManager {
|
|
|
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
|
|
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({
|
|
@@ -122,12 +138,13 @@ class IntegrationManager {
|
|
|
122
138
|
defaultAgencyId: agencyId,
|
|
123
139
|
userId: idUsuario,
|
|
124
140
|
integrationId: this.shipmentType,
|
|
125
|
-
tempShipmentData: parsedOrder
|
|
141
|
+
tempShipmentData: parsedOrder,
|
|
126
142
|
}),
|
|
127
143
|
warehouseId,
|
|
128
144
|
sellerAddress,
|
|
129
145
|
idUsuario,
|
|
130
|
-
group
|
|
146
|
+
group,
|
|
147
|
+
isPriority: yield isPriorityByDefault(),
|
|
131
148
|
});
|
|
132
149
|
}),
|
|
133
150
|
regularExecutionTime: 100, // ms
|
|
@@ -144,14 +161,15 @@ class IntegrationManager {
|
|
|
144
161
|
estaAgrupado
|
|
145
162
|
});
|
|
146
163
|
yield this.insertUserDefaultConfigurationContent({
|
|
147
|
-
|
|
164
|
+
user,
|
|
148
165
|
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
|
|
149
166
|
});
|
|
150
167
|
return filteredOrders;
|
|
151
168
|
});
|
|
152
169
|
}
|
|
153
170
|
insertUserDefaultConfigurationContent(_a) {
|
|
154
|
-
return __awaiter(this, arguments, void 0, function* ({
|
|
171
|
+
return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
|
|
172
|
+
const idUsuario = user.id_usuario;
|
|
155
173
|
const { usersService, configurationService, integrationsService } = this.services;
|
|
156
174
|
const insert = (data, tempShimpmentId) => __awaiter(this, void 0, void 0, function* () {
|
|
157
175
|
return Promise.allSettled(data.map((tempContent) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -166,7 +184,6 @@ class IntegrationManager {
|
|
|
166
184
|
yield insert(userSavedData, order);
|
|
167
185
|
}
|
|
168
186
|
else {
|
|
169
|
-
const user = yield usersService.obtenerUsuarioId(idUsuario);
|
|
170
187
|
const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
|
|
171
188
|
yield insert(userFakeData, order);
|
|
172
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 {
|
|
@@ -45,6 +48,7 @@ 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;
|
|
@@ -56,7 +60,8 @@ export class IntegrationManager {
|
|
|
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;
|
|
@@ -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,18 +94,33 @@ export class IntegrationManager {
|
|
|
88
94
|
type: this.type
|
|
89
95
|
});
|
|
90
96
|
|
|
91
|
-
const
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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({
|
|
@@ -108,12 +129,13 @@ export class IntegrationManager {
|
|
|
108
129
|
defaultAgencyId: agencyId,
|
|
109
130
|
userId: idUsuario,
|
|
110
131
|
integrationId: this.shipmentType,
|
|
111
|
-
tempShipmentData: parsedOrder
|
|
132
|
+
tempShipmentData: parsedOrder,
|
|
112
133
|
}),
|
|
113
134
|
warehouseId,
|
|
114
135
|
sellerAddress,
|
|
115
136
|
idUsuario,
|
|
116
|
-
group
|
|
137
|
+
group,
|
|
138
|
+
isPriority: await isPriorityByDefault(),
|
|
117
139
|
});
|
|
118
140
|
},
|
|
119
141
|
regularExecutionTime: 100, // ms
|
|
@@ -133,7 +155,7 @@ export class IntegrationManager {
|
|
|
133
155
|
});
|
|
134
156
|
|
|
135
157
|
await this.insertUserDefaultConfigurationContent({
|
|
136
|
-
|
|
158
|
+
user,
|
|
137
159
|
tempShimpmentIds: successfullShipments.map(
|
|
138
160
|
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
139
161
|
)
|
|
@@ -143,12 +165,13 @@ export class IntegrationManager {
|
|
|
143
165
|
}
|
|
144
166
|
|
|
145
167
|
async insertUserDefaultConfigurationContent({
|
|
146
|
-
|
|
168
|
+
user,
|
|
147
169
|
tempShimpmentIds
|
|
148
170
|
}: {
|
|
149
|
-
|
|
171
|
+
user: { id_usuario: number, dni: string };
|
|
150
172
|
tempShimpmentIds: number[];
|
|
151
173
|
}) {
|
|
174
|
+
const idUsuario = user.id_usuario
|
|
152
175
|
const { usersService, configurationService, integrationsService } =
|
|
153
176
|
this.services;
|
|
154
177
|
|
|
@@ -179,7 +202,6 @@ export class IntegrationManager {
|
|
|
179
202
|
if (userSavedData.length > 0) {
|
|
180
203
|
await insert(userSavedData, order);
|
|
181
204
|
} else {
|
|
182
|
-
const user = await usersService.obtenerUsuarioId(idUsuario);
|
|
183
205
|
const userFakeData =
|
|
184
206
|
configurationService.getFakeDefaultProformaConfiguration(
|
|
185
207
|
idUsuario,
|
|
@@ -199,7 +221,8 @@ export class IntegrationManager {
|
|
|
199
221
|
warehouseId,
|
|
200
222
|
sellerAddress,
|
|
201
223
|
idUsuario,
|
|
202
|
-
group
|
|
224
|
+
group,
|
|
225
|
+
isPriority
|
|
203
226
|
}: {
|
|
204
227
|
order: ModifiedOrder;
|
|
205
228
|
agencyId: number;
|
|
@@ -207,13 +230,15 @@ export class IntegrationManager {
|
|
|
207
230
|
sellerAddress: SellerAddress;
|
|
208
231
|
idUsuario: number;
|
|
209
232
|
group: Group;
|
|
233
|
+
isPriority: IsPriority
|
|
210
234
|
}): Promise<ModifiedOrderExtended> => {
|
|
211
235
|
const idEnvioTemporal = await this.insertTempShipment({
|
|
212
236
|
order,
|
|
213
237
|
agencyId,
|
|
214
238
|
warehouseId,
|
|
215
239
|
sellerAddress,
|
|
216
|
-
idUsuario
|
|
240
|
+
idUsuario,
|
|
241
|
+
isPriority,
|
|
217
242
|
});
|
|
218
243
|
|
|
219
244
|
if (!idEnvioTemporal)
|
|
@@ -235,13 +260,15 @@ export class IntegrationManager {
|
|
|
235
260
|
agencyId,
|
|
236
261
|
warehouseId,
|
|
237
262
|
sellerAddress,
|
|
238
|
-
idUsuario
|
|
263
|
+
idUsuario,
|
|
264
|
+
isPriority
|
|
239
265
|
}: {
|
|
240
266
|
order: ModifiedOrder;
|
|
241
267
|
agencyId: number;
|
|
242
268
|
warehouseId: number;
|
|
243
269
|
sellerAddress: SellerAddress;
|
|
244
270
|
idUsuario: number;
|
|
271
|
+
isPriority: IsPriority
|
|
245
272
|
}) => {
|
|
246
273
|
const tempShipmentData = await cookTempShipment({
|
|
247
274
|
order,
|
|
@@ -251,7 +278,8 @@ export class IntegrationManager {
|
|
|
251
278
|
sellerAddress,
|
|
252
279
|
idUsuario,
|
|
253
280
|
findNextPickupDate: this.findNextPickupDate,
|
|
254
|
-
countriesService: this.services.countriesService
|
|
281
|
+
countriesService: this.services.countriesService,
|
|
282
|
+
isPriority
|
|
255
283
|
});
|
|
256
284
|
|
|
257
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
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;
|