cardus 0.0.32 → 0.0.34
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 +42 -36
- package/index.ts +68 -71
- package/package.json +1 -1
- package/types/index.ts +42 -2
package/dist/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.IntegrationManager = void 0;
|
|
16
16
|
const moment_1 = __importDefault(require("moment"));
|
|
17
17
|
const insertTempShipment_1 = require("./insertTempShipment");
|
|
18
|
+
const dataToInsert = {
|
|
19
|
+
lines: [],
|
|
20
|
+
contents: [],
|
|
21
|
+
details: [],
|
|
22
|
+
externals: [],
|
|
23
|
+
};
|
|
18
24
|
class IntegrationManager {
|
|
19
25
|
constructor(params) {
|
|
20
26
|
this.insertOrder = (_a) => __awaiter(this, [_a], void 0, function* ({ order, agencyId, warehouseId, sellerAddress, idUsuario, group, isPriority }) {
|
|
@@ -28,7 +34,7 @@ class IntegrationManager {
|
|
|
28
34
|
});
|
|
29
35
|
if (!idEnvioTemporal)
|
|
30
36
|
throw new Error('Temp shipments could not be created');
|
|
31
|
-
|
|
37
|
+
this.insertExternalShipment({
|
|
32
38
|
idUsuario,
|
|
33
39
|
order,
|
|
34
40
|
idEnvioTemporal
|
|
@@ -52,8 +58,8 @@ class IntegrationManager {
|
|
|
52
58
|
});
|
|
53
59
|
return yield this.services.integrationsService.insertTempShipment(tempShipmentData);
|
|
54
60
|
});
|
|
55
|
-
this.insertExternalShipment = (
|
|
56
|
-
|
|
61
|
+
this.insertExternalShipment = ({ idUsuario, order, idEnvioTemporal }) => {
|
|
62
|
+
dataToInsert.externals.push({
|
|
57
63
|
id_envio_temporal_usuario: idEnvioTemporal,
|
|
58
64
|
codigo_envio_externo: order.codigoEnvioExterno,
|
|
59
65
|
id_usuario: idUsuario,
|
|
@@ -67,12 +73,11 @@ class IntegrationManager {
|
|
|
67
73
|
id_documento_holded: order.idDocumentoHolded,
|
|
68
74
|
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
69
75
|
});
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
this.insertTempShipmentLines = (_d) => __awaiter(this, [_d], void 0, function* ({ idEnvioTemporal, group }) {
|
|
76
|
+
};
|
|
77
|
+
this.insertTempShipmentLines = (_c) => __awaiter(this, [_c], void 0, function* ({ idEnvioTemporal, group }) {
|
|
73
78
|
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
74
|
-
if (grouped)
|
|
75
|
-
|
|
79
|
+
if (grouped) {
|
|
80
|
+
dataToInsert.lines.push({
|
|
76
81
|
id_envio: idEnvioTemporal,
|
|
77
82
|
bulto: {
|
|
78
83
|
peso: group.weight,
|
|
@@ -81,6 +86,7 @@ class IntegrationManager {
|
|
|
81
86
|
largo: group.length
|
|
82
87
|
}
|
|
83
88
|
});
|
|
89
|
+
}
|
|
84
90
|
});
|
|
85
91
|
this.services = {
|
|
86
92
|
integrationsService: params.integrationsService,
|
|
@@ -164,39 +170,40 @@ class IntegrationManager {
|
|
|
164
170
|
user,
|
|
165
171
|
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
|
|
166
172
|
});
|
|
173
|
+
yield integrationsService.insertTempShipmentMultipleLines(dataToInsert.lines);
|
|
174
|
+
yield integrationsService.insertTempShipmentMultipleDetails(dataToInsert.details);
|
|
175
|
+
yield integrationsService.insertTempShipmentMultipleContents(dataToInsert.contents);
|
|
176
|
+
yield integrationsService.insertTempShipmentMultipleExternals(dataToInsert.externals);
|
|
167
177
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
168
178
|
});
|
|
169
179
|
}
|
|
170
180
|
insertUserDefaultConfigurationContent(_a) {
|
|
171
181
|
return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
|
|
172
182
|
const idUsuario = user.id_usuario;
|
|
173
|
-
const {
|
|
174
|
-
const insert = (data, tempShimpmentId) =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}).upload();
|
|
183
|
+
const { configurationService } = this.services;
|
|
184
|
+
const insert = (data, tempShimpmentId) => {
|
|
185
|
+
data.forEach((tempContent) => {
|
|
186
|
+
dataToInsert.contents.push(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
let userConfiguration = null;
|
|
190
|
+
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
|
|
191
|
+
if (userSavedData.length === 0) {
|
|
192
|
+
userConfiguration = userSavedData;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
|
|
196
|
+
userConfiguration = userFakeData;
|
|
197
|
+
}
|
|
198
|
+
if (userConfiguration && userConfiguration !== null) {
|
|
199
|
+
tempShimpmentIds.forEach(tempShimpmentId => {
|
|
200
|
+
insert(userConfiguration, tempShimpmentId);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
194
203
|
});
|
|
195
204
|
}
|
|
196
205
|
insertQuantityRelatedLines(_a) {
|
|
197
206
|
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
|
|
198
|
-
const { integrationsService } = this.services;
|
|
199
|
-
const quantityRelatedFunctions = [];
|
|
200
207
|
const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
|
|
201
208
|
if (!idEnvioTemporal)
|
|
202
209
|
return null;
|
|
@@ -222,22 +229,21 @@ class IntegrationManager {
|
|
|
222
229
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
223
230
|
arrayFake.forEach(() => {
|
|
224
231
|
if (!estaAgrupado) {
|
|
225
|
-
|
|
232
|
+
dataToInsert.lines.push({
|
|
226
233
|
id_envio: idEnvioTemporal,
|
|
227
234
|
bulto
|
|
228
|
-
})
|
|
235
|
+
});
|
|
229
236
|
}
|
|
230
|
-
|
|
237
|
+
dataToInsert.details.push({
|
|
231
238
|
id_envio: idEnvioTemporal,
|
|
232
239
|
bulto
|
|
233
|
-
})
|
|
240
|
+
});
|
|
234
241
|
});
|
|
235
242
|
}
|
|
236
243
|
catch (e) {
|
|
237
244
|
console.log(e);
|
|
238
245
|
}
|
|
239
246
|
});
|
|
240
|
-
yield Promise.allSettled(quantityRelatedFunctions);
|
|
241
247
|
});
|
|
242
248
|
}
|
|
243
249
|
}
|
package/index.ts
CHANGED
|
@@ -22,9 +22,17 @@ import {
|
|
|
22
22
|
UserDefaultConfigurationContent,
|
|
23
23
|
GetAgencyIdForTempShipment,
|
|
24
24
|
IsPriority,
|
|
25
|
-
CustomizationService
|
|
25
|
+
CustomizationService,
|
|
26
|
+
DataToInsert,
|
|
26
27
|
} from './types';
|
|
27
28
|
|
|
29
|
+
const dataToInsert: DataToInsert = {
|
|
30
|
+
lines: [],
|
|
31
|
+
contents: [],
|
|
32
|
+
details: [],
|
|
33
|
+
externals: [],
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
interface Services {
|
|
29
37
|
integrationsService: IntegrationsService;
|
|
30
38
|
addressesService: AddressesService;
|
|
@@ -96,7 +104,7 @@ export class IntegrationManager {
|
|
|
96
104
|
|
|
97
105
|
const isPriorityByDefault = async () => {
|
|
98
106
|
const usuariosGeneiPriority = await this.services.customizationService.getUsersWithSection(8);
|
|
99
|
-
|
|
107
|
+
const esPotencialmentePriority = usuariosGeneiPriority.some(
|
|
100
108
|
(seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any; }) =>
|
|
101
109
|
seccion.id_usuario === user.id_usuario ||
|
|
102
110
|
seccion.tipo_cliente === user.tipo_cliente ||
|
|
@@ -160,6 +168,10 @@ export class IntegrationManager {
|
|
|
160
168
|
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
161
169
|
)
|
|
162
170
|
});
|
|
171
|
+
await integrationsService.insertTempShipmentMultipleLines(dataToInsert.lines);
|
|
172
|
+
await integrationsService.insertTempShipmentMultipleDetails(dataToInsert.details);
|
|
173
|
+
await integrationsService.insertTempShipmentMultipleContents(dataToInsert.contents);
|
|
174
|
+
await integrationsService.insertTempShipmentMultipleExternals(dataToInsert.externals);
|
|
163
175
|
|
|
164
176
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
165
177
|
}
|
|
@@ -172,47 +184,42 @@ export class IntegrationManager {
|
|
|
172
184
|
tempShimpmentIds: number[];
|
|
173
185
|
}) {
|
|
174
186
|
const idUsuario = user.id_usuario
|
|
175
|
-
const {
|
|
187
|
+
const { configurationService } =
|
|
176
188
|
this.services;
|
|
177
189
|
|
|
178
|
-
const insert =
|
|
190
|
+
const insert = (
|
|
179
191
|
data: UserDefaultConfigurationContent[],
|
|
180
192
|
tempShimpmentId: number
|
|
181
193
|
) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
await integrationsService.insertTempContent({
|
|
194
|
+
data.forEach((tempContent) => {
|
|
195
|
+
dataToInsert.contents.push({
|
|
185
196
|
...tempContent,
|
|
186
|
-
|
|
187
197
|
id_envio: tempShimpmentId
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
);
|
|
198
|
+
});
|
|
199
|
+
})
|
|
191
200
|
};
|
|
192
201
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
executable: async (order: any) => {
|
|
197
|
-
const userSavedData =
|
|
202
|
+
let userConfiguration: UserDefaultConfigurationContent[] | any = null;
|
|
203
|
+
const userSavedData =
|
|
198
204
|
(await configurationService.getDefaultProformaConfiguration(
|
|
199
205
|
idUsuario
|
|
200
206
|
)) || [];
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
207
|
+
if (userSavedData.length === 0){
|
|
208
|
+
userConfiguration = userSavedData;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const userFakeData =
|
|
212
|
+
configurationService.getFakeDefaultProformaConfiguration(
|
|
213
|
+
idUsuario,
|
|
214
|
+
user.dni
|
|
215
|
+
);
|
|
216
|
+
userConfiguration = userFakeData;
|
|
217
|
+
}
|
|
218
|
+
if (userConfiguration && userConfiguration !== null){
|
|
219
|
+
tempShimpmentIds.forEach(tempShimpmentId => {
|
|
220
|
+
insert(userConfiguration, tempShimpmentId);
|
|
221
|
+
})
|
|
222
|
+
}
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
insertOrder = async ({
|
|
@@ -244,7 +251,7 @@ export class IntegrationManager {
|
|
|
244
251
|
if (!idEnvioTemporal)
|
|
245
252
|
throw new Error('Temp shipments could not be created');
|
|
246
253
|
|
|
247
|
-
|
|
254
|
+
this.insertExternalShipment({
|
|
248
255
|
idUsuario,
|
|
249
256
|
order,
|
|
250
257
|
idEnvioTemporal
|
|
@@ -287,7 +294,7 @@ export class IntegrationManager {
|
|
|
287
294
|
);
|
|
288
295
|
};
|
|
289
296
|
|
|
290
|
-
insertExternalShipment =
|
|
297
|
+
insertExternalShipment = ({
|
|
291
298
|
idUsuario,
|
|
292
299
|
order,
|
|
293
300
|
idEnvioTemporal
|
|
@@ -295,24 +302,22 @@ export class IntegrationManager {
|
|
|
295
302
|
idUsuario: number;
|
|
296
303
|
order: ModifiedOrder;
|
|
297
304
|
idEnvioTemporal: number;
|
|
298
|
-
}):
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
return idEnvioExterno;
|
|
305
|
+
}): undefined => {
|
|
306
|
+
|
|
307
|
+
dataToInsert.externals.push({
|
|
308
|
+
id_envio_temporal_usuario: idEnvioTemporal,
|
|
309
|
+
codigo_envio_externo: order.codigoEnvioExterno,
|
|
310
|
+
id_usuario: idUsuario,
|
|
311
|
+
fecha_hora_creacion: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
312
|
+
servicio: this.type,
|
|
313
|
+
id_interno_shopify: order.idInternoShopify,
|
|
314
|
+
fecha_creacion_externa: moment(order?.fechaCreacionExterna).isValid()
|
|
315
|
+
? moment(order.fechaCreacionExterna).format('YYYY-MM-DD HH:mm:ss')
|
|
316
|
+
: null,
|
|
317
|
+
marketplaceId: order.marketplaceId,
|
|
318
|
+
id_documento_holded: order.idDocumentoHolded,
|
|
319
|
+
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
320
|
+
})
|
|
316
321
|
};
|
|
317
322
|
|
|
318
323
|
insertTempShipmentLines = async ({
|
|
@@ -324,8 +329,8 @@ export class IntegrationManager {
|
|
|
324
329
|
}) => {
|
|
325
330
|
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
326
331
|
|
|
327
|
-
if (grouped)
|
|
328
|
-
|
|
332
|
+
if (grouped) {
|
|
333
|
+
dataToInsert.lines.push({
|
|
329
334
|
id_envio: idEnvioTemporal,
|
|
330
335
|
bulto: {
|
|
331
336
|
peso: group.weight,
|
|
@@ -333,7 +338,8 @@ export class IntegrationManager {
|
|
|
333
338
|
ancho: group.width,
|
|
334
339
|
largo: group.length
|
|
335
340
|
}
|
|
336
|
-
})
|
|
341
|
+
})
|
|
342
|
+
}
|
|
337
343
|
};
|
|
338
344
|
|
|
339
345
|
async insertQuantityRelatedLines({
|
|
@@ -347,8 +353,6 @@ export class IntegrationManager {
|
|
|
347
353
|
crearBulto: CrearBulto;
|
|
348
354
|
estaAgrupado: boolean;
|
|
349
355
|
}) {
|
|
350
|
-
const { integrationsService } = this.services;
|
|
351
|
-
const quantityRelatedFunctions: Array<Promise<undefined>> = [];
|
|
352
356
|
|
|
353
357
|
const obtenerBultosYCantidades = orders.map(
|
|
354
358
|
async ({ idEnvioTemporal, lineas }) => {
|
|
@@ -384,27 +388,20 @@ export class IntegrationManager {
|
|
|
384
388
|
|
|
385
389
|
arrayFake.forEach(() => {
|
|
386
390
|
if (!estaAgrupado) {
|
|
387
|
-
|
|
388
|
-
integrationsService.insertTempShipmentLines({
|
|
389
|
-
id_envio: idEnvioTemporal,
|
|
390
|
-
|
|
391
|
-
bulto
|
|
392
|
-
})
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
quantityRelatedFunctions.push(
|
|
397
|
-
integrationsService.insertTempDetailsShipment({
|
|
391
|
+
dataToInsert.lines.push({
|
|
398
392
|
id_envio: idEnvioTemporal,
|
|
399
393
|
bulto
|
|
400
|
-
})
|
|
401
|
-
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
dataToInsert.details.push({
|
|
397
|
+
id_envio: idEnvioTemporal,
|
|
398
|
+
bulto
|
|
399
|
+
});
|
|
402
400
|
});
|
|
401
|
+
|
|
403
402
|
} catch (e) {
|
|
404
403
|
console.log(e);
|
|
405
404
|
}
|
|
406
405
|
});
|
|
407
|
-
|
|
408
|
-
await Promise.allSettled(quantityRelatedFunctions);
|
|
409
406
|
}
|
|
410
407
|
}
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -107,7 +107,6 @@ type FetchAllOrders = () => Promise<OriginalOrder[]>;
|
|
|
107
107
|
|
|
108
108
|
export type CrearBulto = (params: {
|
|
109
109
|
lineItems: { idEnvioTemporal: number; line: AnyObject };
|
|
110
|
-
|
|
111
110
|
idUsuario: number;
|
|
112
111
|
}) => Promise<Bulto>;
|
|
113
112
|
|
|
@@ -182,6 +181,14 @@ export type IntegrationsService = {
|
|
|
182
181
|
insertTempContent: (
|
|
183
182
|
params: UserDefaultConfigurationContent & { id_envio: number }
|
|
184
183
|
) => Promise<number | false>;
|
|
184
|
+
|
|
185
|
+
insertTempShipmentMultipleLines: (lines: DataToInsert["lines"]) => number | false;
|
|
186
|
+
|
|
187
|
+
insertTempShipmentMultipleDetails: (details: DataToInsert["details"]) => number | false;
|
|
188
|
+
|
|
189
|
+
insertTempShipmentMultipleContents: (contents: DataToInsert["contents"]) => number | false;
|
|
190
|
+
|
|
191
|
+
insertTempShipmentMultipleExternals: (externals: DataToInsert["externals"]) => number | false;
|
|
185
192
|
};
|
|
186
193
|
|
|
187
194
|
export type SellerAddress = {
|
|
@@ -304,4 +311,37 @@ export type GetAgencyIdForTempShipment = (params: {
|
|
|
304
311
|
export type ExecutionManager = {
|
|
305
312
|
upload(): ExecutionManagerUploadReturn[];
|
|
306
313
|
new (params: ExecutionManagerConstructorParams): ExecutionManager;
|
|
307
|
-
};
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export type DataToInsert = {
|
|
317
|
+
lines: InsertContentShipmentLine[];
|
|
318
|
+
contents: InsertContentShipmentData[];
|
|
319
|
+
details: InsertContentShipmentDetail[];
|
|
320
|
+
externals: InsertContentShipmentExternal[];
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
type InsertContentShipmentLine = {
|
|
324
|
+
id_envio: number,
|
|
325
|
+
bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
type InsertContentShipmentData =
|
|
329
|
+
UserDefaultConfigurationContent & { id_envio: number }
|
|
330
|
+
|
|
331
|
+
type InsertContentShipmentDetail = {
|
|
332
|
+
id_envio: number;
|
|
333
|
+
bulto: Bulto['bulto'];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
type InsertContentShipmentExternal = {
|
|
337
|
+
id_envio_temporal_usuario: number;
|
|
338
|
+
codigo_envio_externo: string;
|
|
339
|
+
id_usuario: number;
|
|
340
|
+
fecha_hora_creacion: string;
|
|
341
|
+
servicio: Type;
|
|
342
|
+
id_interno_shopify?: string;
|
|
343
|
+
fecha_creacion_externa: string | null;
|
|
344
|
+
marketplaceId?: string | null;
|
|
345
|
+
id_documento_holded?: string;
|
|
346
|
+
tipo_documento_holded?: string;
|
|
347
|
+
}
|