cardus 0.0.38 → 0.0.39
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 +8 -7
- package/index.ts +43 -40
- package/insertTempShipment/index.ts +2 -8
- package/package.json +2 -2
- package/types/index.ts +35 -26
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ const dataToInsert = {
|
|
|
19
19
|
lines: [],
|
|
20
20
|
contents: [],
|
|
21
21
|
details: [],
|
|
22
|
-
externals: []
|
|
22
|
+
externals: []
|
|
23
23
|
};
|
|
24
24
|
class IntegrationManager {
|
|
25
25
|
constructor(params) {
|
|
@@ -30,7 +30,7 @@ class IntegrationManager {
|
|
|
30
30
|
warehouseId,
|
|
31
31
|
sellerAddress,
|
|
32
32
|
idUsuario,
|
|
33
|
-
isPriority
|
|
33
|
+
isPriority
|
|
34
34
|
});
|
|
35
35
|
if (!idEnvioTemporal)
|
|
36
36
|
throw new Error('Temp shipments could not be created');
|
|
@@ -94,7 +94,7 @@ class IntegrationManager {
|
|
|
94
94
|
countriesService: params.countriesService,
|
|
95
95
|
configurationService: params.configurationService,
|
|
96
96
|
usersService: params.usersService,
|
|
97
|
-
customizationService: params.customizationService
|
|
97
|
+
customizationService: params.customizationService
|
|
98
98
|
};
|
|
99
99
|
this.shipmentType = params.shipmentType;
|
|
100
100
|
this.type = params.type;
|
|
@@ -143,13 +143,13 @@ class IntegrationManager {
|
|
|
143
143
|
defaultAgencyId: agencyId,
|
|
144
144
|
userId: idUsuario,
|
|
145
145
|
integrationId: this.shipmentType,
|
|
146
|
-
tempShipmentData: parsedOrder
|
|
146
|
+
tempShipmentData: parsedOrder
|
|
147
147
|
}),
|
|
148
148
|
warehouseId,
|
|
149
149
|
sellerAddress,
|
|
150
150
|
idUsuario,
|
|
151
151
|
group,
|
|
152
|
-
isPriority: isPriorityByDefault
|
|
152
|
+
isPriority: isPriorityByDefault
|
|
153
153
|
});
|
|
154
154
|
}),
|
|
155
155
|
regularExecutionTime: 8000, // ms
|
|
@@ -186,7 +186,8 @@ class IntegrationManager {
|
|
|
186
186
|
});
|
|
187
187
|
};
|
|
188
188
|
let userConfiguration = null;
|
|
189
|
-
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
|
|
189
|
+
const userSavedData = (yield configurationService.getDefaultProformaConfiguration(idUsuario)) ||
|
|
190
|
+
[];
|
|
190
191
|
if (userSavedData.length > 0) {
|
|
191
192
|
userConfiguration = userSavedData;
|
|
192
193
|
}
|
|
@@ -195,7 +196,7 @@ class IntegrationManager {
|
|
|
195
196
|
userConfiguration = userFakeData;
|
|
196
197
|
}
|
|
197
198
|
if (userConfiguration && userConfiguration !== null) {
|
|
198
|
-
tempShimpmentIds.forEach(tempShimpmentId => {
|
|
199
|
+
tempShimpmentIds.forEach((tempShimpmentId) => {
|
|
199
200
|
insert(userConfiguration, tempShimpmentId);
|
|
200
201
|
});
|
|
201
202
|
}
|
package/index.ts
CHANGED
|
@@ -23,15 +23,15 @@ import {
|
|
|
23
23
|
GetAgencyIdForTempShipment,
|
|
24
24
|
IsPriority,
|
|
25
25
|
CustomizationService,
|
|
26
|
-
DataToInsert
|
|
26
|
+
DataToInsert
|
|
27
27
|
} from './types';
|
|
28
28
|
|
|
29
29
|
const dataToInsert: DataToInsert = {
|
|
30
30
|
lines: [],
|
|
31
31
|
contents: [],
|
|
32
32
|
details: [],
|
|
33
|
-
externals: []
|
|
34
|
-
}
|
|
33
|
+
externals: []
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
interface Services {
|
|
37
37
|
integrationsService: IntegrationsService;
|
|
@@ -69,7 +69,7 @@ export class IntegrationManager {
|
|
|
69
69
|
countriesService: params.countriesService,
|
|
70
70
|
configurationService: params.configurationService,
|
|
71
71
|
usersService: params.usersService,
|
|
72
|
-
customizationService: params.customizationService
|
|
72
|
+
customizationService: params.customizationService
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
this.shipmentType = params.shipmentType;
|
|
@@ -104,9 +104,10 @@ export class IntegrationManager {
|
|
|
104
104
|
|
|
105
105
|
const checkIsPriorityByDefault = async () => {
|
|
106
106
|
// TODO sacar esto de aqui, no hay que hacerlo cada vez, con una vale
|
|
107
|
-
const usuariosGeneiPriority =
|
|
107
|
+
const usuariosGeneiPriority =
|
|
108
|
+
await this.services.customizationService.getUsersWithSection(8);
|
|
108
109
|
const esPotencialmentePriority = usuariosGeneiPriority.some(
|
|
109
|
-
(seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any
|
|
110
|
+
(seccion: { id_usuario: any; tipo_cliente: any; id_comercial: any }) =>
|
|
110
111
|
seccion.id_usuario === user.id_usuario ||
|
|
111
112
|
seccion.tipo_cliente === user.tipo_cliente ||
|
|
112
113
|
seccion.id_comercial === user.id_comercial
|
|
@@ -119,7 +120,7 @@ export class IntegrationManager {
|
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
122
|
|
|
122
|
-
const isPriorityByDefault = await checkIsPriorityByDefault()
|
|
123
|
+
const isPriorityByDefault = await checkIsPriorityByDefault();
|
|
123
124
|
|
|
124
125
|
const insertOrdersResult = await new this.executionManager({
|
|
125
126
|
arrayParams: allOrders,
|
|
@@ -134,13 +135,13 @@ export class IntegrationManager {
|
|
|
134
135
|
defaultAgencyId: agencyId,
|
|
135
136
|
userId: idUsuario,
|
|
136
137
|
integrationId: this.shipmentType,
|
|
137
|
-
tempShipmentData: parsedOrder
|
|
138
|
+
tempShipmentData: parsedOrder
|
|
138
139
|
}),
|
|
139
140
|
warehouseId,
|
|
140
141
|
sellerAddress,
|
|
141
142
|
idUsuario,
|
|
142
143
|
group,
|
|
143
|
-
isPriority: isPriorityByDefault
|
|
144
|
+
isPriority: isPriorityByDefault
|
|
144
145
|
});
|
|
145
146
|
},
|
|
146
147
|
regularExecutionTime: 8000, // ms
|
|
@@ -165,10 +166,18 @@ export class IntegrationManager {
|
|
|
165
166
|
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
166
167
|
)
|
|
167
168
|
});
|
|
168
|
-
await integrationsService.insertTempShipmentMultipleLines(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
await integrationsService.
|
|
169
|
+
await integrationsService.insertTempShipmentMultipleLines(
|
|
170
|
+
dataToInsert.lines
|
|
171
|
+
);
|
|
172
|
+
await integrationsService.insertTempShipmentMultipleDetails(
|
|
173
|
+
dataToInsert.details
|
|
174
|
+
);
|
|
175
|
+
await integrationsService.insertTempShipmentMultipleContents(
|
|
176
|
+
dataToInsert.contents
|
|
177
|
+
);
|
|
178
|
+
await integrationsService.insertTempShipmentMultipleExternals(
|
|
179
|
+
dataToInsert.externals
|
|
180
|
+
);
|
|
172
181
|
|
|
173
182
|
return { filteredOrders, insertedTempShipments: successfullShipments };
|
|
174
183
|
}
|
|
@@ -177,34 +186,31 @@ export class IntegrationManager {
|
|
|
177
186
|
user,
|
|
178
187
|
tempShimpmentIds
|
|
179
188
|
}: {
|
|
180
|
-
user: { id_usuario: number
|
|
189
|
+
user: { id_usuario: number; dni: string };
|
|
181
190
|
tempShimpmentIds: number[];
|
|
182
191
|
}) {
|
|
183
|
-
const idUsuario = user.id_usuario
|
|
184
|
-
const { configurationService } =
|
|
185
|
-
this.services;
|
|
192
|
+
const idUsuario = user.id_usuario;
|
|
193
|
+
const { configurationService } = this.services;
|
|
186
194
|
|
|
187
195
|
const insert = (
|
|
188
196
|
data: UserDefaultConfigurationContent[],
|
|
189
197
|
tempShimpmentId: number
|
|
190
198
|
) => {
|
|
191
199
|
data.forEach((tempContent) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
})
|
|
200
|
+
dataToInsert.contents.push({
|
|
201
|
+
...tempContent,
|
|
202
|
+
id_envio: tempShimpmentId
|
|
203
|
+
});
|
|
204
|
+
});
|
|
197
205
|
};
|
|
198
206
|
|
|
199
207
|
let userConfiguration: UserDefaultConfigurationContent[] | any = null;
|
|
200
208
|
const userSavedData =
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (userSavedData.length > 0){
|
|
209
|
+
(await configurationService.getDefaultProformaConfiguration(idUsuario)) ||
|
|
210
|
+
[];
|
|
211
|
+
if (userSavedData.length > 0) {
|
|
205
212
|
userConfiguration = userSavedData;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
213
|
+
} else {
|
|
208
214
|
const userFakeData =
|
|
209
215
|
configurationService.getFakeDefaultProformaConfiguration(
|
|
210
216
|
idUsuario,
|
|
@@ -212,10 +218,10 @@ export class IntegrationManager {
|
|
|
212
218
|
);
|
|
213
219
|
userConfiguration = userFakeData;
|
|
214
220
|
}
|
|
215
|
-
if (userConfiguration && userConfiguration !== null){
|
|
216
|
-
tempShimpmentIds.forEach(tempShimpmentId => {
|
|
221
|
+
if (userConfiguration && userConfiguration !== null) {
|
|
222
|
+
tempShimpmentIds.forEach((tempShimpmentId) => {
|
|
217
223
|
insert(userConfiguration, tempShimpmentId);
|
|
218
|
-
})
|
|
224
|
+
});
|
|
219
225
|
}
|
|
220
226
|
}
|
|
221
227
|
|
|
@@ -234,7 +240,7 @@ export class IntegrationManager {
|
|
|
234
240
|
sellerAddress: SellerAddress;
|
|
235
241
|
idUsuario: number;
|
|
236
242
|
group: Group;
|
|
237
|
-
isPriority: IsPriority
|
|
243
|
+
isPriority: IsPriority;
|
|
238
244
|
}): Promise<ModifiedOrderExtended> => {
|
|
239
245
|
const idEnvioTemporal = await this.insertTempShipment({
|
|
240
246
|
order,
|
|
@@ -242,7 +248,7 @@ export class IntegrationManager {
|
|
|
242
248
|
warehouseId,
|
|
243
249
|
sellerAddress,
|
|
244
250
|
idUsuario,
|
|
245
|
-
isPriority
|
|
251
|
+
isPriority
|
|
246
252
|
});
|
|
247
253
|
|
|
248
254
|
if (!idEnvioTemporal)
|
|
@@ -272,7 +278,7 @@ export class IntegrationManager {
|
|
|
272
278
|
warehouseId: number;
|
|
273
279
|
sellerAddress: SellerAddress;
|
|
274
280
|
idUsuario: number;
|
|
275
|
-
isPriority: IsPriority
|
|
281
|
+
isPriority: IsPriority;
|
|
276
282
|
}) => {
|
|
277
283
|
const tempShipmentData = await cookTempShipment({
|
|
278
284
|
order,
|
|
@@ -301,7 +307,6 @@ export class IntegrationManager {
|
|
|
301
307
|
order: ModifiedOrder;
|
|
302
308
|
idEnvioTemporal: number;
|
|
303
309
|
}): undefined => {
|
|
304
|
-
|
|
305
310
|
dataToInsert.externals.push({
|
|
306
311
|
id_envio_temporal_usuario: idEnvioTemporal,
|
|
307
312
|
codigo_envio_externo: order.codigoEnvioExterno,
|
|
@@ -315,7 +320,7 @@ export class IntegrationManager {
|
|
|
315
320
|
marketplaceId: order.marketplaceId,
|
|
316
321
|
id_documento_holded: order.idDocumentoHolded,
|
|
317
322
|
tipo_documento_holded: order.tipoDocumentoHolded || ''
|
|
318
|
-
|
|
323
|
+
});
|
|
319
324
|
};
|
|
320
325
|
|
|
321
326
|
insertTempShipmentLines = async ({
|
|
@@ -336,7 +341,7 @@ export class IntegrationManager {
|
|
|
336
341
|
ancho: group.width,
|
|
337
342
|
largo: group.length
|
|
338
343
|
}
|
|
339
|
-
})
|
|
344
|
+
});
|
|
340
345
|
}
|
|
341
346
|
};
|
|
342
347
|
|
|
@@ -351,7 +356,6 @@ export class IntegrationManager {
|
|
|
351
356
|
crearBulto: CrearBulto;
|
|
352
357
|
estaAgrupado: boolean;
|
|
353
358
|
}) {
|
|
354
|
-
|
|
355
359
|
const obtenerBultosYCantidades = orders.map(
|
|
356
360
|
async ({ idEnvioTemporal, lineas }) => {
|
|
357
361
|
if (!idEnvioTemporal) return null;
|
|
@@ -396,10 +400,9 @@ export class IntegrationManager {
|
|
|
396
400
|
bulto
|
|
397
401
|
});
|
|
398
402
|
});
|
|
399
|
-
|
|
400
403
|
} catch (e) {
|
|
401
404
|
console.log(e);
|
|
402
405
|
}
|
|
403
406
|
});
|
|
404
407
|
}
|
|
405
|
-
}
|
|
408
|
+
}
|
|
@@ -30,7 +30,7 @@ export const cookTempShipment = async ({
|
|
|
30
30
|
idUsuario: number;
|
|
31
31
|
findNextPickupDate: FindNextPickupDate;
|
|
32
32
|
countriesService: CountriesService;
|
|
33
|
-
isPriority: IsPriority
|
|
33
|
+
isPriority: IsPriority;
|
|
34
34
|
}): Promise<Shipment> => {
|
|
35
35
|
let zonaLLegada = {};
|
|
36
36
|
if (order.codigoPaisLLegada)
|
|
@@ -54,7 +54,6 @@ export const cookTempShipment = async ({
|
|
|
54
54
|
mail_salida: sellerAddress.mail
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
|
|
58
57
|
const setUbicacionComprador = async (order: ModifiedOrder) => {
|
|
59
58
|
type CompradorLocation = {
|
|
60
59
|
pais_llegada: string | null;
|
|
@@ -62,7 +61,6 @@ export const cookTempShipment = async ({
|
|
|
62
61
|
id_zona_llegada: string | null;
|
|
63
62
|
};
|
|
64
63
|
|
|
65
|
-
|
|
66
64
|
const compradorLocation: CompradorLocation = {
|
|
67
65
|
pais_llegada: null,
|
|
68
66
|
provincia_llegada: null,
|
|
@@ -93,7 +91,6 @@ export const cookTempShipment = async ({
|
|
|
93
91
|
return compradorLocation;
|
|
94
92
|
};
|
|
95
93
|
|
|
96
|
-
|
|
97
94
|
const setDatosComprador = async (order: ModifiedOrder) => ({
|
|
98
95
|
nom_ape_llegada: order.primerApellidoLLegada
|
|
99
96
|
? order.nombreLLegada + ' ' + order.primerApellidoLLegada
|
|
@@ -113,12 +110,10 @@ export const cookTempShipment = async ({
|
|
|
113
110
|
mail_llegada: order.emailLLegada || 'no informado'
|
|
114
111
|
});
|
|
115
112
|
|
|
116
|
-
|
|
117
113
|
const setReembolso = (order: ModifiedOrder) => {
|
|
118
114
|
return { cantidad_contrareembolso: order.cantidadContrareembolso };
|
|
119
115
|
};
|
|
120
116
|
|
|
121
|
-
|
|
122
117
|
const setFechas = async (order: ModifiedOrder) => {
|
|
123
118
|
const date = moment().format('YYYY-MM-DD');
|
|
124
119
|
const beginHour = '09:00';
|
|
@@ -179,8 +174,7 @@ export const cookTempShipment = async ({
|
|
|
179
174
|
...stepResult,
|
|
180
175
|
priority: isPriority
|
|
181
176
|
};
|
|
182
|
-
|
|
183
177
|
}, {})) as Shipment;
|
|
184
178
|
|
|
185
179
|
return dataInsert;
|
|
186
|
-
};
|
|
180
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cardus",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "an integration manager",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rm -rf dist && tsc --build",
|
|
9
|
-
"prepublishOnly": "npm run build",
|
|
9
|
+
"prepublishOnly": "npm run format && npm run build",
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts && npm run format",
|
|
12
12
|
"format": "prettier --config .prettierrc './**/*.ts' --write"
|
package/types/index.ts
CHANGED
|
@@ -182,13 +182,21 @@ export type IntegrationsService = {
|
|
|
182
182
|
params: UserDefaultConfigurationContent & { id_envio: number }
|
|
183
183
|
) => Promise<number | false>;
|
|
184
184
|
|
|
185
|
-
insertTempShipmentMultipleLines: (
|
|
185
|
+
insertTempShipmentMultipleLines: (
|
|
186
|
+
lines: DataToInsert['lines']
|
|
187
|
+
) => number | false;
|
|
186
188
|
|
|
187
|
-
insertTempShipmentMultipleDetails: (
|
|
189
|
+
insertTempShipmentMultipleDetails: (
|
|
190
|
+
details: DataToInsert['details']
|
|
191
|
+
) => number | false;
|
|
188
192
|
|
|
189
|
-
insertTempShipmentMultipleContents: (
|
|
193
|
+
insertTempShipmentMultipleContents: (
|
|
194
|
+
contents: DataToInsert['contents']
|
|
195
|
+
) => number | false;
|
|
190
196
|
|
|
191
|
-
insertTempShipmentMultipleExternals: (
|
|
197
|
+
insertTempShipmentMultipleExternals: (
|
|
198
|
+
externals: DataToInsert['externals']
|
|
199
|
+
) => number | false;
|
|
192
200
|
};
|
|
193
201
|
|
|
194
202
|
export type SellerAddress = {
|
|
@@ -269,7 +277,7 @@ export type ConfigurationService = {
|
|
|
269
277
|
) => UserDefaultConfigurationContent[];
|
|
270
278
|
};
|
|
271
279
|
|
|
272
|
-
export type IsPriority = number
|
|
280
|
+
export type IsPriority = number;
|
|
273
281
|
|
|
274
282
|
export type UsersService = {
|
|
275
283
|
obtenerUsuarioId: (id_usuario: number) => Promise<User>;
|
|
@@ -277,7 +285,7 @@ export type UsersService = {
|
|
|
277
285
|
|
|
278
286
|
export type CustomizationService = {
|
|
279
287
|
getUsersWithSection: (seccion: number) => Promise<User[]>;
|
|
280
|
-
}
|
|
288
|
+
};
|
|
281
289
|
|
|
282
290
|
export type FindNextPickupDate = (params: {
|
|
283
291
|
fecha?: string;
|
|
@@ -321,27 +329,28 @@ export type DataToInsert = {
|
|
|
321
329
|
};
|
|
322
330
|
|
|
323
331
|
type InsertContentShipmentLine = {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
332
|
+
id_envio: number;
|
|
333
|
+
bulto: Pick<Bulto['bulto'], 'peso' | 'alto' | 'ancho' | 'largo'>;
|
|
334
|
+
};
|
|
327
335
|
|
|
328
|
-
type InsertContentShipmentData =
|
|
329
|
-
|
|
336
|
+
type InsertContentShipmentData = UserDefaultConfigurationContent & {
|
|
337
|
+
id_envio: number;
|
|
338
|
+
};
|
|
330
339
|
|
|
331
340
|
type InsertContentShipmentDetail = {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
341
|
+
id_envio: number;
|
|
342
|
+
bulto: Bulto['bulto'];
|
|
343
|
+
};
|
|
335
344
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
345
|
+
type InsertContentShipmentExternal = {
|
|
346
|
+
id_envio_temporal_usuario: number;
|
|
347
|
+
codigo_envio_externo: string;
|
|
348
|
+
id_usuario: number;
|
|
349
|
+
fecha_hora_creacion: string;
|
|
350
|
+
servicio: Type;
|
|
351
|
+
id_interno_shopify?: string;
|
|
352
|
+
fecha_creacion_externa: string | null;
|
|
353
|
+
marketplaceId?: string | null;
|
|
354
|
+
id_documento_holded?: string;
|
|
355
|
+
tipo_documento_holded?: string;
|
|
356
|
+
};
|