cardus 0.0.33 → 0.0.35
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 +37 -41
- package/index.ts +60 -75
- 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,
|
|
@@ -119,6 +118,7 @@ class IntegrationManager {
|
|
|
119
118
|
type: this.type
|
|
120
119
|
});
|
|
121
120
|
const isPriorityByDefault = () => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
// TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
|
|
122
122
|
const usuariosGeneiPriority = yield this.services.customizationService.getUsersWithSection(8);
|
|
123
123
|
const esPotencialmentePriority = usuariosGeneiPriority.some((seccion) => seccion.id_usuario === user.id_usuario ||
|
|
124
124
|
seccion.tipo_cliente === user.tipo_cliente ||
|
|
@@ -136,9 +136,6 @@ class IntegrationManager {
|
|
|
136
136
|
const parsedOrder = yield modificarOrdenOriginal({
|
|
137
137
|
originalOrder: order
|
|
138
138
|
});
|
|
139
|
-
const duplicatedTempShipment = yield integrationsService.checkDuplicateTempShipment(parsedOrder.codigoEnvioExterno, idUsuario);
|
|
140
|
-
if (duplicatedTempShipment)
|
|
141
|
-
throw new Error('Envio Duplicado');
|
|
142
139
|
return this.insertOrder({
|
|
143
140
|
order: parsedOrder,
|
|
144
141
|
agencyId: yield this.getAgencyIdForTempShipment({
|
|
@@ -171,39 +168,40 @@ class IntegrationManager {
|
|
|
171
168
|
user,
|
|
172
169
|
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal)
|
|
173
170
|
});
|
|
171
|
+
yield integrationsService.insertTempShipmentMultipleLines(dataToInsert.lines);
|
|
172
|
+
yield integrationsService.insertTempShipmentMultipleDetails(dataToInsert.details);
|
|
173
|
+
yield integrationsService.insertTempShipmentMultipleContents(dataToInsert.contents);
|
|
174
|
+
yield integrationsService.insertTempShipmentMultipleExternals(dataToInsert.externals);
|
|
174
175
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
178
|
insertUserDefaultConfigurationContent(_a) {
|
|
178
179
|
return __awaiter(this, arguments, void 0, function* ({ user, tempShimpmentIds }) {
|
|
179
180
|
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();
|
|
181
|
+
const { configurationService } = this.services;
|
|
182
|
+
const insert = (data, tempShimpmentId) => {
|
|
183
|
+
data.forEach((tempContent) => {
|
|
184
|
+
dataToInsert.contents.push(Object.assign(Object.assign({}, tempContent), { id_envio: tempShimpmentId }));
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
let userConfiguration = null;
|
|
188
|
+
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) || [];
|
|
189
|
+
if (userSavedData.length === 0) {
|
|
190
|
+
userConfiguration = userSavedData;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const userFakeData = configurationService.getFakeDefaultProformaConfiguration(idUsuario, user.dni);
|
|
194
|
+
userConfiguration = userFakeData;
|
|
195
|
+
}
|
|
196
|
+
if (userConfiguration && userConfiguration !== null) {
|
|
197
|
+
tempShimpmentIds.forEach(tempShimpmentId => {
|
|
198
|
+
insert(userConfiguration, tempShimpmentId);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
insertQuantityRelatedLines(_a) {
|
|
204
204
|
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, estaAgrupado }) {
|
|
205
|
-
const { integrationsService } = this.services;
|
|
206
|
-
const quantityRelatedFunctions = [];
|
|
207
205
|
const obtenerBultosYCantidades = orders.map((_b) => __awaiter(this, [_b], void 0, function* ({ idEnvioTemporal, lineas }) {
|
|
208
206
|
if (!idEnvioTemporal)
|
|
209
207
|
return null;
|
|
@@ -234,18 +232,16 @@ class IntegrationManager {
|
|
|
234
232
|
bulto
|
|
235
233
|
});
|
|
236
234
|
}
|
|
237
|
-
|
|
238
|
-
quantityRelatedFunctions.push(integrationsService.insertTempDetailsShipment({
|
|
235
|
+
dataToInsert.details.push({
|
|
239
236
|
id_envio: idEnvioTemporal,
|
|
240
237
|
bulto
|
|
241
|
-
})
|
|
238
|
+
});
|
|
242
239
|
});
|
|
243
240
|
}
|
|
244
241
|
catch (e) {
|
|
245
242
|
console.log(e);
|
|
246
243
|
}
|
|
247
244
|
});
|
|
248
|
-
yield Promise.allSettled(quantityRelatedFunctions);
|
|
249
245
|
});
|
|
250
246
|
}
|
|
251
247
|
}
|
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 {
|
|
@@ -104,8 +103,9 @@ export class IntegrationManager {
|
|
|
104
103
|
});
|
|
105
104
|
|
|
106
105
|
const isPriorityByDefault = async () => {
|
|
106
|
+
// TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
|
|
107
107
|
const usuariosGeneiPriority = await this.services.customizationService.getUsersWithSection(8);
|
|
108
|
-
|
|
108
|
+
const esPotencialmentePriority = usuariosGeneiPriority.some(
|
|
109
109
|
(seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any; }) =>
|
|
110
110
|
seccion.id_usuario === user.id_usuario ||
|
|
111
111
|
seccion.tipo_cliente === user.tipo_cliente ||
|
|
@@ -126,12 +126,6 @@ export class IntegrationManager {
|
|
|
126
126
|
originalOrder: order
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
const duplicatedTempShipment = await integrationsService.checkDuplicateTempShipment(
|
|
130
|
-
parsedOrder.codigoEnvioExterno,
|
|
131
|
-
idUsuario
|
|
132
|
-
);
|
|
133
|
-
if (duplicatedTempShipment) throw new Error('Envio Duplicado');
|
|
134
|
-
|
|
135
129
|
return this.insertOrder({
|
|
136
130
|
order: parsedOrder,
|
|
137
131
|
agencyId: await this.getAgencyIdForTempShipment({
|
|
@@ -169,6 +163,10 @@ export class IntegrationManager {
|
|
|
169
163
|
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
170
164
|
)
|
|
171
165
|
});
|
|
166
|
+
await integrationsService.insertTempShipmentMultipleLines(dataToInsert.lines);
|
|
167
|
+
await integrationsService.insertTempShipmentMultipleDetails(dataToInsert.details);
|
|
168
|
+
await integrationsService.insertTempShipmentMultipleContents(dataToInsert.contents);
|
|
169
|
+
await integrationsService.insertTempShipmentMultipleExternals(dataToInsert.externals);
|
|
172
170
|
|
|
173
171
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
174
172
|
}
|
|
@@ -181,47 +179,42 @@ export class IntegrationManager {
|
|
|
181
179
|
tempShimpmentIds: number[];
|
|
182
180
|
}) {
|
|
183
181
|
const idUsuario = user.id_usuario
|
|
184
|
-
const {
|
|
182
|
+
const { configurationService } =
|
|
185
183
|
this.services;
|
|
186
184
|
|
|
187
|
-
const insert =
|
|
185
|
+
const insert = (
|
|
188
186
|
data: UserDefaultConfigurationContent[],
|
|
189
187
|
tempShimpmentId: number
|
|
190
188
|
) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
await integrationsService.insertTempContent({
|
|
189
|
+
data.forEach((tempContent) => {
|
|
190
|
+
dataToInsert.contents.push({
|
|
194
191
|
...tempContent,
|
|
195
|
-
|
|
196
192
|
id_envio: tempShimpmentId
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
);
|
|
193
|
+
});
|
|
194
|
+
})
|
|
200
195
|
};
|
|
201
196
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
executable: async (order: any) => {
|
|
206
|
-
const userSavedData =
|
|
197
|
+
let userConfiguration: UserDefaultConfigurationContent[] | any = null;
|
|
198
|
+
const userSavedData =
|
|
207
199
|
(await configurationService.getDefaultProformaConfiguration(
|
|
208
200
|
idUsuario
|
|
209
201
|
)) || [];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
202
|
+
if (userSavedData.length === 0){
|
|
203
|
+
userConfiguration = userSavedData;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const userFakeData =
|
|
207
|
+
configurationService.getFakeDefaultProformaConfiguration(
|
|
208
|
+
idUsuario,
|
|
209
|
+
user.dni
|
|
210
|
+
);
|
|
211
|
+
userConfiguration = userFakeData;
|
|
212
|
+
}
|
|
213
|
+
if (userConfiguration && userConfiguration !== null){
|
|
214
|
+
tempShimpmentIds.forEach(tempShimpmentId => {
|
|
215
|
+
insert(userConfiguration, tempShimpmentId);
|
|
216
|
+
})
|
|
217
|
+
}
|
|
225
218
|
}
|
|
226
219
|
|
|
227
220
|
insertOrder = async ({
|
|
@@ -253,7 +246,7 @@ export class IntegrationManager {
|
|
|
253
246
|
if (!idEnvioTemporal)
|
|
254
247
|
throw new Error('Temp shipments could not be created');
|
|
255
248
|
|
|
256
|
-
|
|
249
|
+
this.insertExternalShipment({
|
|
257
250
|
idUsuario,
|
|
258
251
|
order,
|
|
259
252
|
idEnvioTemporal
|
|
@@ -296,7 +289,7 @@ export class IntegrationManager {
|
|
|
296
289
|
);
|
|
297
290
|
};
|
|
298
291
|
|
|
299
|
-
insertExternalShipment =
|
|
292
|
+
insertExternalShipment = ({
|
|
300
293
|
idUsuario,
|
|
301
294
|
order,
|
|
302
295
|
idEnvioTemporal
|
|
@@ -304,24 +297,22 @@ export class IntegrationManager {
|
|
|
304
297
|
idUsuario: number;
|
|
305
298
|
order: ModifiedOrder;
|
|
306
299
|
idEnvioTemporal: number;
|
|
307
|
-
}):
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
return idEnvioExterno;
|
|
300
|
+
}): undefined => {
|
|
301
|
+
|
|
302
|
+
dataToInsert.externals.push({
|
|
303
|
+
id_envio_temporal_usuario: idEnvioTemporal,
|
|
304
|
+
codigo_envio_externo: order.codigoEnvioExterno,
|
|
305
|
+
id_usuario: idUsuario,
|
|
306
|
+
fecha_hora_creacion: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
307
|
+
servicio: this.type,
|
|
308
|
+
id_interno_shopify: order.idInternoShopify,
|
|
309
|
+
fecha_creacion_externa: moment(order?.fechaCreacionExterna).isValid()
|
|
310
|
+
? moment(order.fechaCreacionExterna).format('YYYY-MM-DD HH:mm:ss')
|
|
311
|
+
: null,
|
|
312
|
+
marketplaceId: order.marketplaceId,
|
|
313
|
+
id_documento_holded: order.idDocumentoHolded,
|
|
314
|
+
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
315
|
+
})
|
|
325
316
|
};
|
|
326
317
|
|
|
327
318
|
insertTempShipmentLines = async ({
|
|
@@ -333,8 +324,8 @@ export class IntegrationManager {
|
|
|
333
324
|
}) => {
|
|
334
325
|
const grouped = group.grouped === 1 || group.grouped === '1';
|
|
335
326
|
|
|
336
|
-
if (grouped)
|
|
337
|
-
|
|
327
|
+
if (grouped) {
|
|
328
|
+
dataToInsert.lines.push({
|
|
338
329
|
id_envio: idEnvioTemporal,
|
|
339
330
|
bulto: {
|
|
340
331
|
peso: group.weight,
|
|
@@ -342,7 +333,8 @@ export class IntegrationManager {
|
|
|
342
333
|
ancho: group.width,
|
|
343
334
|
largo: group.length
|
|
344
335
|
}
|
|
345
|
-
})
|
|
336
|
+
})
|
|
337
|
+
}
|
|
346
338
|
};
|
|
347
339
|
|
|
348
340
|
async insertQuantityRelatedLines({
|
|
@@ -356,8 +348,6 @@ export class IntegrationManager {
|
|
|
356
348
|
crearBulto: CrearBulto;
|
|
357
349
|
estaAgrupado: boolean;
|
|
358
350
|
}) {
|
|
359
|
-
const { integrationsService } = this.services;
|
|
360
|
-
const quantityRelatedFunctions: Array<Promise<undefined>> = [];
|
|
361
351
|
|
|
362
352
|
const obtenerBultosYCantidades = orders.map(
|
|
363
353
|
async ({ idEnvioTemporal, lineas }) => {
|
|
@@ -394,24 +384,19 @@ export class IntegrationManager {
|
|
|
394
384
|
arrayFake.forEach(() => {
|
|
395
385
|
if (!estaAgrupado) {
|
|
396
386
|
dataToInsert.lines.push({
|
|
397
|
-
id_envio: idEnvioTemporal,
|
|
387
|
+
id_envio: idEnvioTemporal,
|
|
398
388
|
bulto
|
|
399
389
|
});
|
|
400
390
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
id_envio: idEnvioTemporal,
|
|
406
|
-
bulto
|
|
407
|
-
})
|
|
408
|
-
);
|
|
391
|
+
dataToInsert.details.push({
|
|
392
|
+
id_envio: idEnvioTemporal,
|
|
393
|
+
bulto
|
|
394
|
+
});
|
|
409
395
|
});
|
|
396
|
+
|
|
410
397
|
} catch (e) {
|
|
411
398
|
console.log(e);
|
|
412
399
|
}
|
|
413
400
|
});
|
|
414
|
-
|
|
415
|
-
await Promise.allSettled(quantityRelatedFunctions);
|
|
416
401
|
}
|
|
417
402
|
}
|
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
|
+
}
|