cardus 0.0.33 → 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 +36 -38
- package/index.ts +59 -69
- package/package.json +1 -1
- package/types/index.ts +38 -11
package/dist/index.js
CHANGED
|
@@ -16,11 +16,10 @@ exports.IntegrationManager = void 0;
|
|
|
16
16
|
const moment_1 = __importDefault(require("moment"));
|
|
17
17
|
const insertTempShipment_1 = require("./insertTempShipment");
|
|
18
18
|
const dataToInsert = {
|
|
19
|
-
tempShipment: [],
|
|
20
19
|
lines: [],
|
|
21
|
-
|
|
20
|
+
contents: [],
|
|
22
21
|
details: [],
|
|
23
|
-
|
|
22
|
+
externals: [],
|
|
24
23
|
};
|
|
25
24
|
class IntegrationManager {
|
|
26
25
|
constructor(params) {
|
|
@@ -35,7 +34,7 @@ class IntegrationManager {
|
|
|
35
34
|
});
|
|
36
35
|
if (!idEnvioTemporal)
|
|
37
36
|
throw new Error('Temp shipments could not be created');
|
|
38
|
-
|
|
37
|
+
this.insertExternalShipment({
|
|
39
38
|
idUsuario,
|
|
40
39
|
order,
|
|
41
40
|
idEnvioTemporal
|
|
@@ -59,8 +58,8 @@ class IntegrationManager {
|
|
|
59
58
|
});
|
|
60
59
|
return yield this.services.integrationsService.insertTempShipment(tempShipmentData);
|
|
61
60
|
});
|
|
62
|
-
this.insertExternalShipment = (
|
|
63
|
-
|
|
61
|
+
this.insertExternalShipment = ({ idUsuario, order, idEnvioTemporal }) => {
|
|
62
|
+
dataToInsert.externals.push({
|
|
64
63
|
id_envio_temporal_usuario: idEnvioTemporal,
|
|
65
64
|
codigo_envio_externo: order.codigoEnvioExterno,
|
|
66
65
|
id_usuario: idUsuario,
|
|
@@ -74,12 +73,11 @@ class IntegrationManager {
|
|
|
74
73
|
id_documento_holded: order.idDocumentoHolded,
|
|
75
74
|
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
76
75
|
});
|
|
77
|
-
|
|
78
|
-
})
|
|
79
|
-
this.insertTempShipmentLines = (_d) => __awaiter(this, [_d], void 0, function* ({ idEnvioTemporal, group }) {
|
|
76
|
+
};
|
|
77
|
+
this.insertTempShipmentLines = (_c) => __awaiter(this, [_c], void 0, function* ({ idEnvioTemporal, group }) {
|
|
80
78
|
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
81
|
-
if (grouped)
|
|
82
|
-
|
|
79
|
+
if (grouped) {
|
|
80
|
+
dataToInsert.lines.push({
|
|
83
81
|
id_envio: idEnvioTemporal,
|
|
84
82
|
bulto: {
|
|
85
83
|
peso: group.weight,
|
|
@@ -88,6 +86,7 @@ class IntegrationManager {
|
|
|
88
86
|
largo: group.length
|
|
89
87
|
}
|
|
90
88
|
});
|
|
89
|
+
}
|
|
91
90
|
});
|
|
92
91
|
this.services = {
|
|
93
92
|
integrationsService: params.integrationsService,
|
|
@@ -171,39 +170,40 @@ class IntegrationManager {
|
|
|
171
170
|
user,
|
|
172
171
|
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
|
|
173
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);
|
|
174
177
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
180
|
insertUserDefaultConfigurationContent(_a) {
|
|
178
181
|
return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
|
|
179
182
|
const idUsuario = user.id_usuario;
|
|
180
|
-
const {
|
|
181
|
-
const insert = (data, tempShimpmentId) =>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}).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
|
+
}
|
|
201
203
|
});
|
|
202
204
|
}
|
|
203
205
|
insertQuantityRelatedLines(_a) {
|
|
204
206
|
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
|
|
205
|
-
const { integrationsService } = this.services;
|
|
206
|
-
const quantityRelatedFunctions = [];
|
|
207
207
|
const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
|
|
208
208
|
if (!idEnvioTemporal)
|
|
209
209
|
return null;
|
|
@@ -234,18 +234,16 @@ class IntegrationManager {
|
|
|
234
234
|
bulto
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
|
-
|
|
238
|
-
quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({
|
|
237
|
+
dataToInsert.details.push({
|
|
239
238
|
id_envio: idEnvioTemporal,
|
|
240
239
|
bulto
|
|
241
|
-
})
|
|
240
|
+
});
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
243
|
catch (e) {
|
|
245
244
|
console.log(e);
|
|
246
245
|
}
|
|
247
246
|
});
|
|
248
|
-
yield Promise.allSettled(quantityRelatedFunctions);
|
|
249
247
|
});
|
|
250
248
|
}
|
|
251
249
|
}
|
package/index.ts
CHANGED
|
@@ -27,11 +27,10 @@ import {
|
|
|
27
27
|
} from './types';
|
|
28
28
|
|
|
29
29
|
const dataToInsert: DataToInsert = {
|
|
30
|
-
tempShipment: [],
|
|
31
30
|
lines: [],
|
|
32
|
-
|
|
31
|
+
contents: [],
|
|
33
32
|
details: [],
|
|
34
|
-
|
|
33
|
+
externals: [],
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
interface Services {
|
|
@@ -105,7 +104,7 @@ export class IntegrationManager {
|
|
|
105
104
|
|
|
106
105
|
const isPriorityByDefault = async () => {
|
|
107
106
|
const usuariosGeneiPriority = await this.services.customizationService.getUsersWithSection(8);
|
|
108
|
-
|
|
107
|
+
const esPotencialmentePriority = usuariosGeneiPriority.some(
|
|
109
108
|
(seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any; }) =>
|
|
110
109
|
seccion.id_usuario === user.id_usuario ||
|
|
111
110
|
seccion.tipo_cliente === user.tipo_cliente ||
|
|
@@ -169,6 +168,10 @@ export class IntegrationManager {
|
|
|
169
168
|
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
170
169
|
)
|
|
171
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);
|
|
172
175
|
|
|
173
176
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
174
177
|
}
|
|
@@ -181,47 +184,42 @@ export class IntegrationManager {
|
|
|
181
184
|
tempShimpmentIds: number[];
|
|
182
185
|
}) {
|
|
183
186
|
const idUsuario = user.id_usuario
|
|
184
|
-
const {
|
|
187
|
+
const { configurationService } =
|
|
185
188
|
this.services;
|
|
186
189
|
|
|
187
|
-
const insert =
|
|
190
|
+
const insert = (
|
|
188
191
|
data: UserDefaultConfigurationContent[],
|
|
189
192
|
tempShimpmentId: number
|
|
190
193
|
) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
await integrationsService.insertTempContent({
|
|
194
|
+
data.forEach((tempContent) => {
|
|
195
|
+
dataToInsert.contents.push({
|
|
194
196
|
...tempContent,
|
|
195
|
-
|
|
196
197
|
id_envio: tempShimpmentId
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
);
|
|
198
|
+
});
|
|
199
|
+
})
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
executable: async (order: any) => {
|
|
206
|
-
const userSavedData =
|
|
202
|
+
let userConfiguration: UserDefaultConfigurationContent[] | any = null;
|
|
203
|
+
const userSavedData =
|
|
207
204
|
(await configurationService.getDefaultProformaConfiguration(
|
|
208
205
|
idUsuario
|
|
209
206
|
)) || [];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
}
|
|
225
223
|
}
|
|
226
224
|
|
|
227
225
|
insertOrder = async ({
|
|
@@ -253,7 +251,7 @@ export class IntegrationManager {
|
|
|
253
251
|
if (!idEnvioTemporal)
|
|
254
252
|
throw new Error('Temp shipments could not be created');
|
|
255
253
|
|
|
256
|
-
|
|
254
|
+
this.insertExternalShipment({
|
|
257
255
|
idUsuario,
|
|
258
256
|
order,
|
|
259
257
|
idEnvioTemporal
|
|
@@ -296,7 +294,7 @@ export class IntegrationManager {
|
|
|
296
294
|
);
|
|
297
295
|
};
|
|
298
296
|
|
|
299
|
-
insertExternalShipment =
|
|
297
|
+
insertExternalShipment = ({
|
|
300
298
|
idUsuario,
|
|
301
299
|
order,
|
|
302
300
|
idEnvioTemporal
|
|
@@ -304,24 +302,22 @@ export class IntegrationManager {
|
|
|
304
302
|
idUsuario: number;
|
|
305
303
|
order: ModifiedOrder;
|
|
306
304
|
idEnvioTemporal: number;
|
|
307
|
-
}):
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
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
|
+
})
|
|
325
321
|
};
|
|
326
322
|
|
|
327
323
|
insertTempShipmentLines = async ({
|
|
@@ -333,8 +329,8 @@ export class IntegrationManager {
|
|
|
333
329
|
}) => {
|
|
334
330
|
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
335
331
|
|
|
336
|
-
if (grouped)
|
|
337
|
-
|
|
332
|
+
if (grouped) {
|
|
333
|
+
dataToInsert.lines.push({
|
|
338
334
|
id_envio: idEnvioTemporal,
|
|
339
335
|
bulto: {
|
|
340
336
|
peso: group.weight,
|
|
@@ -342,7 +338,8 @@ export class IntegrationManager {
|
|
|
342
338
|
ancho: group.width,
|
|
343
339
|
largo: group.length
|
|
344
340
|
}
|
|
345
|
-
})
|
|
341
|
+
})
|
|
342
|
+
}
|
|
346
343
|
};
|
|
347
344
|
|
|
348
345
|
async insertQuantityRelatedLines({
|
|
@@ -356,8 +353,6 @@ export class IntegrationManager {
|
|
|
356
353
|
crearBulto: CrearBulto;
|
|
357
354
|
estaAgrupado: boolean;
|
|
358
355
|
}) {
|
|
359
|
-
const { integrationsService } = this.services;
|
|
360
|
-
const quantityRelatedFunctions: Array<Promise<undefined>> = [];
|
|
361
356
|
|
|
362
357
|
const obtenerBultosYCantidades = orders.map(
|
|
363
358
|
async ({ idEnvioTemporal, lineas }) => {
|
|
@@ -394,24 +389,19 @@ export class IntegrationManager {
|
|
|
394
389
|
arrayFake.forEach(() => {
|
|
395
390
|
if (!estaAgrupado) {
|
|
396
391
|
dataToInsert.lines.push({
|
|
397
|
-
id_envio: idEnvioTemporal,
|
|
392
|
+
id_envio: idEnvioTemporal,
|
|
398
393
|
bulto
|
|
399
394
|
});
|
|
400
395
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
id_envio: idEnvioTemporal,
|
|
406
|
-
bulto
|
|
407
|
-
})
|
|
408
|
-
);
|
|
396
|
+
dataToInsert.details.push({
|
|
397
|
+
id_envio: idEnvioTemporal,
|
|
398
|
+
bulto
|
|
399
|
+
});
|
|
409
400
|
});
|
|
401
|
+
|
|
410
402
|
} catch (e) {
|
|
411
403
|
console.log(e);
|
|
412
404
|
}
|
|
413
405
|
});
|
|
414
|
-
|
|
415
|
-
await Promise.allSettled(quantityRelatedFunctions);
|
|
416
406
|
}
|
|
417
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
|
|
|
@@ -174,8 +173,6 @@ export type IntegrationsService = {
|
|
|
174
173
|
bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
|
|
175
174
|
}) => Promise<undefined>;
|
|
176
175
|
|
|
177
|
-
insertTempShipmentMultipleLines: (lines: DataToInsert["lines"]) => number | false;
|
|
178
|
-
|
|
179
176
|
insertTempDetailsShipment: (params: {
|
|
180
177
|
id_envio: number;
|
|
181
178
|
bulto: Bulto['bulto'];
|
|
@@ -184,6 +181,14 @@ export type IntegrationsService = {
|
|
|
184
181
|
insertTempContent: (
|
|
185
182
|
params: UserDefaultConfigurationContent & { id_envio: number }
|
|
186
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;
|
|
187
192
|
};
|
|
188
193
|
|
|
189
194
|
export type SellerAddress = {
|
|
@@ -309,12 +314,34 @@ export type ExecutionManager = {
|
|
|
309
314
|
};
|
|
310
315
|
|
|
311
316
|
export type DataToInsert = {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}[];
|
|
317
|
-
content: any[];
|
|
318
|
-
details: any[];
|
|
319
|
-
external: any[];
|
|
317
|
+
lines: InsertContentShipmentLine[];
|
|
318
|
+
contents: InsertContentShipmentData[];
|
|
319
|
+
details: InsertContentShipmentDetail[];
|
|
320
|
+
externals: InsertContentShipmentExternal[];
|
|
320
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
|
+
}
|